Skip to content

Commit

Permalink
merge between PolicyAndCookieBanner component and footer, also extend…
Browse files Browse the repository at this point in the history
…ed functionality inside this new component
  • Loading branch information
gaudyb committed Apr 18, 2024
1 parent 6f474db commit d86581b
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 253 deletions.
63 changes: 0 additions & 63 deletions packages/components/src/Footer/Footer.stories.tsx

This file was deleted.

111 changes: 0 additions & 111 deletions packages/components/src/Footer/Footer.tsx

This file was deleted.

59 changes: 0 additions & 59 deletions packages/components/src/Footer/Footer.types.ts

This file was deleted.

6 changes: 0 additions & 6 deletions packages/components/src/Footer/index.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
* Copyright (c) Microsoft. All rights reserved.
* Licensed under the MIT license. See LICENSE file in the project.
*/

import type { StoryFn } from '@storybook/react'

import {
PolicyAndCookieBanner,
defaultBannerLinks,
Expand Down Expand Up @@ -88,3 +85,27 @@ export const AdditionalLinks = {

name: 'Additional links',
}

export const ExtendedItemsCustomization = {
render: (args: PolicyAndCookieBannerProps) => (
<PolicyAndCookieBanner {...args} />
),

args: {
links: [...defaultBannerLinks, { name: 'Clickable', onClick: () => {alert("Testing props")}},],
},

name: 'Extended Items Customization',
}

export const HideShowItemsCustomization = {
render: (args: PolicyAndCookieBannerProps) => (
<PolicyAndCookieBanner {...args} />
),

args: {
links: [...defaultBannerLinks, { name: 'Hide item', href: '', hide: true}, { name: 'Show item', href: ''},],
},

name: 'Hide/Show Items Customization',
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@
import { Link, Text } from '@fluentui/react'

Check warning on line 5 in packages/components/src/PolicyAndCookieBanner/PolicyAndCookieBanner.tsx

View workflow job for this annotation

GitHub Actions / build (18.x)

'/home/runner/work/essex-toolkit/essex-toolkit/.yarn/__virtual__/@fluentui-react-virtual-554103797a/0/cache/@fluentui-react-npm-8.111.1-5600742b95-eec8dc1efc.zip/node_modules/@fluentui/react/lib/index.js' imported multiple times

Check warning on line 5 in packages/components/src/PolicyAndCookieBanner/PolicyAndCookieBanner.tsx

View workflow job for this annotation

GitHub Actions / build (18.x)

'/home/runner/work/essex-toolkit/essex-toolkit/.yarn/__virtual__/@fluentui-react-virtual-554103797a/0/cache/@fluentui-react-npm-8.111.1-5600742b95-eec8dc1efc.zip/node_modules/@fluentui/react/lib/index.js' imported multiple times
import type { CSSProperties, FC } from 'react'
import { memo, useMemo } from 'react'
import { useTheme } from '@fluentui/react'

Check warning on line 8 in packages/components/src/PolicyAndCookieBanner/PolicyAndCookieBanner.tsx

View workflow job for this annotation

GitHub Actions / build (18.x)

'/home/runner/work/essex-toolkit/essex-toolkit/.yarn/__virtual__/@fluentui-react-virtual-554103797a/0/cache/@fluentui-react-npm-8.111.1-5600742b95-eec8dc1efc.zip/node_modules/@fluentui/react/lib/index.js' imported multiple times

Check warning on line 8 in packages/components/src/PolicyAndCookieBanner/PolicyAndCookieBanner.tsx

View workflow job for this annotation

GitHub Actions / build (18.x)

'/home/runner/work/essex-toolkit/essex-toolkit/.yarn/__virtual__/@fluentui-react-virtual-554103797a/0/cache/@fluentui-react-npm-8.111.1-5600742b95-eec8dc1efc.zip/node_modules/@fluentui/react/lib/index.js' imported multiple times

import { useLoadMSFTCookieScript } from './PolicyAndCookieBanner.hooks.js'
import type {
PolicyAndCookieBannerProps,
PolicyLinkDetails,
PolicyLinkProps,
} from './PolicyAndCookieBanner.types.js'
import { Container } from './PolicyAndCookieBanner.styles.js'

const containerStyles: CSSProperties = {
display: 'flex',
Expand Down Expand Up @@ -51,13 +53,13 @@ export const defaultBannerLinks: Array<PolicyLinkDetails> = [
export const PolicyAndCookieBanner: FC<PolicyAndCookieBannerProps> = memo(
function CookieConsentProvider({
language = navigator.language ?? 'en-US',
theme = 'light',
onConsentChange = () => undefined,
onError,
className,
styles,
links = defaultBannerLinks,
}) {
const theme = useTheme()
const divStyles: CSSProperties = useMemo(() => {
return {
...containerStyles,
Expand All @@ -66,22 +68,22 @@ export const PolicyAndCookieBanner: FC<PolicyAndCookieBannerProps> = memo(
}, [styles])

const policyLinks = useMemo(() => {
return links.map(({ name, href }, i) => {
return (
<PolicyLink key={name} divider={i !== 0} name={name} href={href} />
)
return links.map(({ name, href, onClick, hide }, i) => {
return hide === false || hide === undefined ? (
<PolicyLink key={name} divider={i !== 0} name={name} href={href} onClick={onClick}/>
) : null
})
}, [links])

const consentManager = useLoadMSFTCookieScript({
language,
theme,
theme: theme.isInverted ? 'dark' : 'light',
onConsentChange,
onError,
})

return (
<div className={className} style={divStyles}>
<Container className={className} style={divStyles}>
{consentManager?.isConsentRequired && (
<>
<PolicyLink
Expand All @@ -95,7 +97,7 @@ export const PolicyAndCookieBanner: FC<PolicyAndCookieBannerProps> = memo(
</>
)}
{policyLinks}
</div>
</Container>
)
},
)
Expand All @@ -108,11 +110,20 @@ const PolicyLink: FC<PolicyLinkProps> = memo(function PolicyLink({
divider = false,
id,
}) {
return (
return href == null || href === '' ? (
<>
{divider && <Text variant='tiny'>|</Text>}
<Text variant='smallPlus'>
<Link id={id} href={href} target='_blank' onClick={onClick}>
<Link id={id} target='_blank' onClick={onClick}>
{name}
</Link>
</Text>
</>
) : (
<>
{divider && <Text variant='tiny'>|</Text>}
<Text variant='smallPlus'>
<Link id={id} href={href} target='_blank'>
{name}
</Link>
</Text>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export type WcpConsent = {
/**
* @public
*/
export type PolicyLinkDetails = { name: string; href: string }
export type PolicyLinkDetails = { name: string; href?: string; onClick?: () => void; hide?: boolean }

/**
* Defaults to {
Expand Down

0 comments on commit d86581b

Please sign in to comment.