-
Notifications
You must be signed in to change notification settings - Fork 221
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
docs: Refreshing GlobalHeader Storybook Example #2891
Merged
alanbsmith
merged 17 commits into
Workday:master
from
williamjstanton:william-global-header-example-polish
Nov 8, 2024
Merged
Changes from 16 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
f763ced
docs: Adding tooltips to icon buttons
73b31cd
docs: Adding more Tooltips to icon buttons
58a1a72
docs: Updating GlobalHeader story
52818ca
docs: Autocomplete works for now
e5a1c5e
Merge remote-tracking branch 'upstream/master' into william-global-he…
16c7fe7
docs: Setting up Combobox system
27aa407
docs: Fixed styles
99cda61
docs: Setting up Autocomplete combobox
95d5510
docs: Setting up the CountBadge
dcd0bf2
docs: Finishing notifications live badge
870272a
docs: Final polish
849c565
docs: Updating storybook file
71bed75
docs: Adding label for search input
e86563b
Merge branch 'Workday:master' into william-global-header-example-polish
williamjstanton c78fdc9
docs: Fixing styles with new tokens
e937fb5
Merge branch 'master' into william-global-header-example-polish
mannycarrera4 06bf5c5
fix: Clean up story
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
261 changes: 224 additions & 37 deletions
261
modules/react/_examples/stories/examples/GlobalHeader.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,65 +1,252 @@ | ||
import * as React from 'react'; | ||
import {styled, createComponent, dubLogoBlue} from '@workday/canvas-kit-react/common'; | ||
import {colors, depth, space, type} from '@workday/canvas-kit-react/tokens'; | ||
|
||
import { | ||
AccessibleHide, | ||
AriaLiveRegion, | ||
composeHooks, | ||
createComponent, | ||
createElemPropsHook, | ||
createSubcomponent, | ||
ExtractProps, | ||
useUniqueId, | ||
} from '@workday/canvas-kit-react/common'; | ||
import {base, system} from '@workday/canvas-tokens-web'; | ||
import {calc, createStyles, px2rem} from '@workday/canvas-kit-styling'; | ||
import { | ||
notificationsIcon, | ||
inboxIcon, | ||
justifyIcon, | ||
assistantIcon, | ||
searchIcon, | ||
} from '@workday/canvas-system-icons-web'; | ||
|
||
import {TertiaryButton, Hyperlink} from '@workday/canvas-kit-react/button'; | ||
import {SecondaryButton, TertiaryButton} from '@workday/canvas-kit-react/button'; | ||
import {Avatar} from '@workday/canvas-kit-react/avatar'; | ||
import {Flex, FlexProps} from '@workday/canvas-kit-react/layout'; | ||
import {SearchForm} from '@workday/canvas-kit-labs-react/search-form'; | ||
import {Tooltip} from '@workday/canvas-kit-react/tooltip'; | ||
import {Combobox, useComboboxModel, useComboboxInput} from '@workday/canvas-kit-react/combobox'; | ||
import {InputGroup, TextInput} from '@workday/canvas-kit-react/text-input'; | ||
import {StyledMenuItem} from '@workday/canvas-kit-react/menu'; | ||
import {SystemIcon} from '@workday/canvas-kit-react/icon'; | ||
import {CountBadge} from '@workday/canvas-kit-react/badge'; | ||
|
||
interface HeaderItemProps extends FlexProps {} | ||
interface LiveCountBadgeProps extends FlexProps { | ||
cnt: number; | ||
} | ||
|
||
const tasks = ['Request Time Off', 'Create Expense Report', 'Change Benefits']; | ||
|
||
export const Basic = () => ( | ||
<GlobalHeader> | ||
<GlobalHeader.Item> | ||
<TertiaryButton aria-label="menu" icon={justifyIcon} /> | ||
<Hyperlink> | ||
<WorkdayLogo dangerouslySetInnerHTML={{__html: dubLogoBlue}} /> | ||
</Hyperlink> | ||
</GlobalHeader.Item> | ||
<GlobalHeader.Item margin="auto" width="100%" maxWidth={`calc(${space.xxxl} * 6)`}> | ||
<SearchForm onSubmit={() => 1} /> | ||
</GlobalHeader.Item> | ||
<GlobalHeader.Item> | ||
<TertiaryButton aria-label="messages" icon={assistantIcon} /> | ||
<TertiaryButton aria-label="notifications" icon={notificationsIcon} /> | ||
<TertiaryButton aria-label="inbox" icon={inboxIcon} /> | ||
<Avatar size={Avatar.Size.m} variant={Avatar.Variant.Light} /> | ||
</GlobalHeader.Item> | ||
</GlobalHeader> | ||
const styleOverrides = { | ||
headerWrapper: createStyles({ | ||
display: 'flex', | ||
alignItems: 'center', | ||
justifyContent: 'space-between', | ||
boxSizing: 'border-box', | ||
...system.type.subtext.large, | ||
WebkitFontSmoothing: 'antialiased', | ||
MozOsxFontSmoothing: 'grayscale', | ||
backgroundColor: system.color.bg.default, | ||
padding: system.space.x1, | ||
}), | ||
inputGroupInner: createStyles({ | ||
marginLeft: '1rem', | ||
width: px2rem(20), | ||
transition: 'opacity 100ms ease', | ||
}), | ||
comboboxContainer: createStyles({ | ||
margin: 'auto', | ||
width: '100%', | ||
maxWidth: calc.multiply(system.space.x20, 6), | ||
}), | ||
comboboxInput: createStyles({ | ||
borderRadius: px2rem(1000), | ||
width: '20rem', | ||
}), | ||
comboboxMenuList: createStyles({ | ||
maxHeight: px2rem(200), | ||
}), | ||
menuButtonStyles: createStyles({ | ||
textDecoration: 'none', | ||
color: base.blackPepper500, | ||
}), | ||
notificationContainerStyles: createStyles({ | ||
boxSizing: 'border-box', | ||
position: 'relative', | ||
}), | ||
countBadgeStyles: createStyles({ | ||
boxSizing: 'border-box', | ||
position: 'absolute', | ||
top: calc.negate(system.space.x1), | ||
insetInlineEnd: calc.negate(system.space.x1), | ||
}), | ||
actionButtonStyles: createStyles({ | ||
gap: system.space.x4, | ||
margin: system.space.x4, | ||
}), | ||
}; | ||
|
||
const useAutocompleteInput = composeHooks( | ||
createElemPropsHook(useComboboxModel)(model => { | ||
return { | ||
onKeyPress(event: React.KeyboardEvent) { | ||
model.events.show(event); | ||
}, | ||
}; | ||
}), | ||
useComboboxInput | ||
); | ||
|
||
const AutoCompleteInput = createSubcomponent(TextInput)({ | ||
modelHook: useComboboxModel, | ||
elemPropsHook: useAutocompleteInput, | ||
})<ExtractProps<typeof Combobox.Input, never>>((elemProps, Element) => { | ||
return <Combobox.Input as={Element} {...elemProps} />; | ||
}); | ||
|
||
export const Basic = () => { | ||
const [notifications, setNotifications] = React.useState(0); | ||
|
||
function handleAdd() { | ||
setNotifications(prev => prev + 1); | ||
} | ||
|
||
function handleClear() { | ||
setNotifications(0); | ||
} | ||
|
||
return ( | ||
<> | ||
<GlobalHeader> | ||
<GlobalHeader.Item> | ||
<Tooltip title="Global Navigation" type="describe"> | ||
<TertiaryButton icon={justifyIcon} cs={styleOverrides.menuButtonStyles}> | ||
MENU | ||
</TertiaryButton> | ||
</Tooltip> | ||
<Tooltip title="Workday Home"> | ||
<TertiaryButton> | ||
<img src="https://design.workday.com/images/ck-dub-logo-blue.svg" alt="" /> | ||
</TertiaryButton> | ||
</Tooltip> | ||
</GlobalHeader.Item> | ||
<GlobalHeader.Item cs={styleOverrides.comboboxContainer}> | ||
<Autocomplete aria-label="Search Workday" /> | ||
</GlobalHeader.Item> | ||
<GlobalHeader.Item> | ||
<Tooltip title="Assistant"> | ||
<TertiaryButton icon={assistantIcon} /> | ||
</Tooltip> | ||
|
||
<NotificationLiveBadge cnt={notifications} /> | ||
|
||
<Tooltip title="My Tasks"> | ||
<TertiaryButton icon={inboxIcon} /> | ||
</Tooltip> | ||
<Tooltip title="Profile"> | ||
<Avatar /> | ||
</Tooltip> | ||
</GlobalHeader.Item> | ||
</GlobalHeader> | ||
<Flex cs={styleOverrides.actionButtonStyles}> | ||
<SecondaryButton onClick={handleAdd}>Add notification</SecondaryButton> | ||
<TertiaryButton onClick={handleClear}>Clear</TertiaryButton> | ||
</Flex> | ||
</> | ||
); | ||
}; | ||
|
||
const GlobalHeaderItem = createComponent('div')({ | ||
displayName: 'GlobalHeader.Item', | ||
Component: ({gap = 's', ...props}: HeaderItemProps, ref) => ( | ||
<Flex gap={gap} alignItems="center" marginX={space.xs} ref={ref} {...props} /> | ||
<Flex gap={gap} alignItems="center" marginX={system.space.x3} ref={ref} {...props} /> | ||
), | ||
}); | ||
|
||
const GlobalHeader = createComponent('header')({ | ||
displayName: 'GlobalHeader', | ||
Component: (props, ref, Element) => <HeaderWrapper ref={ref} as={Element} {...props} />, | ||
Component: (props, ref) => ( | ||
<header className={styleOverrides.headerWrapper} ref={ref} {...props} /> | ||
), | ||
subComponents: {Item: GlobalHeaderItem}, | ||
}); | ||
|
||
const HeaderWrapper = styled('header')({ | ||
display: 'flex', | ||
alignItems: 'center', | ||
justifyContent: 'space-between', | ||
boxSizing: 'border-box', | ||
...type.levels.subtext.large, | ||
WebkitFontSmoothing: 'antialiased', | ||
MozOsxFontSmoothing: 'grayscale', | ||
backgroundColor: colors.frenchVanilla100, | ||
...depth[1], | ||
padding: space.xxs, | ||
const Autocomplete = createComponent('div')({ | ||
displayName: 'Autocomplete', | ||
Component: props => { | ||
const [searchText, setSearchText] = React.useState(''); | ||
const filteredTasks = tasks.filter(i => { | ||
if (searchText.trim() === '' || typeof searchText !== 'string') { | ||
return true; | ||
} | ||
return i.toLowerCase().includes(searchText.trim().toLowerCase()); | ||
}); | ||
|
||
function handleChange(e) { | ||
setSearchText(e.target.value); | ||
} | ||
|
||
return ( | ||
<Combobox> | ||
<InputGroup> | ||
<InputGroup.InnerStart cs={styleOverrides.inputGroupInner}> | ||
<SystemIcon icon={searchIcon} /> | ||
</InputGroup.InnerStart> | ||
<InputGroup.Input | ||
as={AutoCompleteInput} | ||
cs={styleOverrides.comboboxInput} | ||
onChange={handleChange} | ||
value={searchText} | ||
{...props} | ||
/> | ||
</InputGroup> | ||
<Combobox.Menu.Popper> | ||
<Combobox.Menu.Card> | ||
{filteredTasks.length === 0 ? ( | ||
<StyledMenuItem as="span">No Results Found</StyledMenuItem> | ||
) : ( | ||
filteredTasks.map(i => ( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Although mapping works, we should probably use a render function like in the auto complete example:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll need some help with using this model! |
||
<Combobox.Menu.List cs={styleOverrides.comboboxMenuList}> | ||
<Combobox.Menu.Item key={i}>{i}</Combobox.Menu.Item> | ||
</Combobox.Menu.List> | ||
)) | ||
)} | ||
</Combobox.Menu.Card> | ||
</Combobox.Menu.Popper> | ||
</Combobox> | ||
); | ||
}, | ||
}); | ||
|
||
const WorkdayLogo = styled('span')({lineHeight: 0}); | ||
const NotificationLiveBadge = createComponent('span')({ | ||
displayName: 'NotificationLiveBadge', | ||
Component: ({cnt = 0, ...props}: LiveCountBadgeProps) => { | ||
const btnId = useUniqueId(); | ||
const badgeId = useUniqueId(); | ||
|
||
return ( | ||
<Flex cs={styleOverrides.notificationContainerStyles}> | ||
<Tooltip title="Notifications"> | ||
<TertiaryButton | ||
id={btnId} | ||
icon={notificationsIcon} | ||
aria-describedby={cnt > 0 ? badgeId : undefined} | ||
{...props} | ||
/> | ||
</Tooltip> | ||
<AriaLiveRegion aria-labelledby={btnId}> | ||
{cnt > 0 && ( | ||
<> | ||
<CountBadge | ||
id={badgeId} | ||
count={cnt} | ||
limit={100} | ||
cs={styleOverrides.countBadgeStyles} | ||
/> | ||
<AccessibleHide>New</AccessibleHide> | ||
</> | ||
)} | ||
</AriaLiveRegion> | ||
</Flex> | ||
); | ||
}, | ||
}); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does passing a token here work?