Skip to content

Commit 72efd12

Browse files
committed
Some clean up
1 parent 0cbdf84 commit 72efd12

File tree

3 files changed

+41
-99
lines changed

3 files changed

+41
-99
lines changed

packages/react/src/ActionBar/ActionBar.examples.stories.tsx

Lines changed: 1 addition & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, {type RefObject} from 'react'
1+
import React from 'react'
22
import type {Meta} from '@storybook/react-vite'
33
import ActionBar from '.'
44
import Text from '../Text'
@@ -19,8 +19,6 @@ import {
1919
ThreeBarsIcon,
2020
TrashIcon,
2121
KebabHorizontalIcon,
22-
PeopleIcon,
23-
GearIcon,
2422
} from '@primer/octicons-react'
2523
import {Button, Avatar, ActionMenu, IconButton, ActionList, Textarea} from '..'
2624
import {Dialog} from '../deprecated/DialogV1'
@@ -317,42 +315,6 @@ export const MultipleActionBars = () => {
317315
)
318316
}
319317

320-
const MultiSelect = React.forwardRef((props, ref) => {
321-
type Option = {name: string; selected: boolean}
322-
323-
const [options, setOptions] = React.useState<Option[]>([
324-
{name: 'Show code folding buttons', selected: true},
325-
{name: 'Wrap lines', selected: false},
326-
{name: 'Center content', selected: false},
327-
])
328-
329-
const toggle = (name: string) => {
330-
setOptions(
331-
options.map(option => {
332-
if (option.name === name) option.selected = !option.selected
333-
return option
334-
}),
335-
)
336-
}
337-
338-
return (
339-
<ActionMenu anchorRef={ref as RefObject<HTMLButtonElement>}>
340-
<ActionMenu.Anchor>
341-
<IconButton variant="invisible" aria-label="Formatting" icon={GearIcon} />
342-
</ActionMenu.Anchor>
343-
<ActionMenu.Overlay width="auto">
344-
<ActionList selectionVariant="multiple">
345-
{options.map(options => (
346-
<ActionList.Item key={options.name} selected={options.selected} onSelect={() => toggle(options.name)}>
347-
{options.name}
348-
</ActionList.Item>
349-
))}
350-
</ActionList>
351-
</ActionMenu.Overlay>
352-
</ActionMenu>
353-
)
354-
})
355-
356318
const ActionMenuExample = () => {
357319
return (
358320
<ActionBar.Menu
@@ -388,7 +350,6 @@ export const WithMenus = () => (
388350
/>
389351
<ActionBar.IconButton disabled icon={FileAddedIcon} aria-label="File Added"></ActionBar.IconButton>
390352
<ActionBar.IconButton disabled icon={SearchIcon} aria-label="Search"></ActionBar.IconButton>
391-
<ActionBar.Menu aria-label="Test Menu" icon={PeopleIcon} renderMenu={MultiSelect} />
392353
<ActionBar.IconButton disabled icon={QuoteIcon} aria-label="Insert Quote"></ActionBar.IconButton>
393354
<ActionBar.IconButton icon={ListUnorderedIcon} aria-label="Unordered List"></ActionBar.IconButton>
394355
<ActionBar.IconButton icon={ListOrderedIcon} aria-label="Ordered List"></ActionBar.IconButton>

packages/react/src/ActionBar/ActionBar.module.css

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -43,19 +43,6 @@
4343
}
4444
}
4545

46-
.Menu {
47-
.Divider {
48-
&::before {
49-
border: 0;
50-
height: var(--borderWidth-thin, .0625rem);
51-
margin-block-end: var(--base-size-8, .5rem);
52-
margin-block-start: calc(var(--base-size-8, .5rem) - var(--borderWidth-thin, .0625rem));
53-
padding: 0;
54-
width: unset;
55-
}
56-
}
57-
}
58-
5946
.Group {
6047
display: flex;
6148
gap: inherit;

packages/react/src/ActionBar/ActionBar.tsx

Lines changed: 40 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,21 @@ export type ActionBarProps = {
106106

107107
export type ActionBarIconButtonProps = {disabled?: boolean} & IconButtonProps
108108

109+
export type ActionBarMenuItem = {
110+
disabled?: boolean
111+
icon?: ActionBarIconButtonProps['icon']
112+
label: string
113+
onClick?: ActionListItemProps['onSelect']
114+
} & Pick<ActionListItemProps, 'variant'>
115+
116+
export type ActionBarMenuProps = {
117+
/** Accessible label for the menu button */
118+
'aria-label': string
119+
/** Icon for the menu button */
120+
icon: ActionBarIconButtonProps['icon']
121+
items?: ActionBarMenuItem[]
122+
} & IconButtonProps
123+
109124
const MORE_BTN_WIDTH = 32
110125

111126
const calculatePossibleItems = (
@@ -488,59 +503,38 @@ export const ActionBarGroup = forwardRef(({children}: React.PropsWithChildren, f
488503
)
489504
})
490505

491-
type ActionBarMenuItem = {
492-
disabled?: boolean
493-
icon?: ActionBarIconButtonProps['icon']
494-
label: string
495-
onClick?: ActionListItemProps['onSelect']
496-
} & Pick<ActionListItemProps, 'variant'>
497-
498-
type ActionBarMenuProps = {
499-
/** Accessible label for the menu button */
500-
'aria-label': string // TODO: Change to label
501-
/** Icon for the menu button */
502-
icon: ActionBarIconButtonProps['icon']
503-
items?: ActionBarMenuItem[]
504-
}
505-
506-
const ActionBarMenuContext = React.createContext<{
507-
menuId: string
508-
menuVisible: boolean
509-
label: string
510-
}>({menuId: '', menuVisible: false, label: ''})
511-
512-
export const ActionBarMenu = forwardRef(({'aria-label': ariaLabel, icon, items}: ActionBarMenuProps, forwardedRef) => {
513-
const backupRef = useRef<HTMLButtonElement>(null)
514-
const ref = (forwardedRef ?? backupRef) as RefObject<HTMLButtonElement>
515-
const id = useId()
516-
const {registerChild, unregisterChild, isVisibleChild} = React.useContext(ActionBarContext)
506+
export const ActionBarMenu = forwardRef(
507+
({'aria-label': ariaLabel, icon, items, ...props}: ActionBarMenuProps, forwardedRef) => {
508+
const backupRef = useRef<HTMLButtonElement>(null)
509+
const ref = (forwardedRef ?? backupRef) as RefObject<HTMLButtonElement>
510+
const id = useId()
511+
const {registerChild, unregisterChild, isVisibleChild} = React.useContext(ActionBarContext)
517512

518-
const [menuOpen, setMenuOpen] = useState(false)
513+
const [menuOpen, setMenuOpen] = useState(false)
519514

520-
// Like IconButton, we store the width in a ref to ensure that we don't forget about it when not visible
521-
// If a child has a groupId, it won't be visible if the group isn't visible, so we don't need to check isVisibleChild here
522-
const widthRef = useRef<number>()
515+
// Like IconButton, we store the width in a ref to ensure that we don't forget about it when not visible
516+
// If a child has a groupId, it won't be visible if the group isn't visible, so we don't need to check isVisibleChild here
517+
const widthRef = useRef<number>()
523518

524-
useIsomorphicLayoutEffect(() => {
525-
const width = ref.current?.getBoundingClientRect().width
526-
if (width) widthRef.current = width
519+
useIsomorphicLayoutEffect(() => {
520+
const width = ref.current?.getBoundingClientRect().width
521+
if (width) widthRef.current = width
527522

528-
if (!widthRef.current) return
523+
if (!widthRef.current) return
529524

530-
registerChild(id, {type: 'menu', width: widthRef.current, label: ariaLabel, icon, items})
525+
registerChild(id, {type: 'menu', width: widthRef.current, label: ariaLabel, icon, items})
531526

532-
return () => {
533-
unregisterChild(id)
534-
}
535-
}, [registerChild, unregisterChild])
527+
return () => {
528+
unregisterChild(id)
529+
}
530+
}, [registerChild, unregisterChild])
536531

537-
if (!isVisibleChild(id)) return null
532+
if (!isVisibleChild(id)) return null
538533

539-
return (
540-
<ActionBarMenuContext.Provider value={{menuId: id, menuVisible: isVisibleChild(id), label: ariaLabel}}>
534+
return (
541535
<ActionMenu anchorRef={ref} open={menuOpen} onOpenChange={setMenuOpen}>
542536
<ActionMenu.Anchor>
543-
<IconButton variant="invisible" aria-label={ariaLabel} icon={icon} />
537+
<IconButton variant="invisible" aria-label={ariaLabel} icon={icon} {...props} />
544538
</ActionMenu.Anchor>
545539
<ActionMenu.Overlay>
546540
<ActionList className={styles.Menu}>
@@ -553,9 +547,9 @@ export const ActionBarMenu = forwardRef(({'aria-label': ariaLabel, icon, items}:
553547
</ActionList>
554548
</ActionMenu.Overlay>
555549
</ActionMenu>
556-
</ActionBarMenuContext.Provider>
557-
)
558-
})
550+
)
551+
},
552+
)
559553

560554
export const VerticalDivider = () => {
561555
const ref = useRef<HTMLDivElement>(null)

0 commit comments

Comments
 (0)