-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Auto-generate react-menu * use correct react-menu version * Update packages/react-menu/package.json Co-authored-by: Oleksandr Fediashov <alexander.mcgarret@gmail.com> * update files * remove unnecessary * modified codeowners * update codeowners * modify codeowners * Change files * add react-hooks dep * revert unnecessary files * fix deps * remove unnecessary comments * type ref * use state for selectors * add mising type * remove cast * remove readme * remove default div * remove default div * fix story type * follow package structure * add export * remove placeholder * revert package.json * type refs * Change files * fix deps * move conformance to devdep * update api * fixes to types * remove coment * fix imports * update api * update API * fix types * fix conformance tests * fix exports Co-authored-by: Oleksandr Fediashov <alexander.mcgarret@gmail.com> Co-authored-by: Elizabeth Craig <elcraig@microsoft.com>
- Loading branch information
1 parent
e6a1c49
commit fe4959d
Showing
31 changed files
with
465 additions
and
6 deletions.
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
change/@fluentui-react-examples-9fac4130-8756-47e0-b70d-09925f28c31e.json
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"type": "minor", | ||
"comment": "Implement basic MenuList example", | ||
"packageName": "@fluentui/react-examples", | ||
"email": "lingfan.gao@microsoft.com", | ||
"dependentChangeType": "patch" | ||
} |
7 changes: 7 additions & 0 deletions
7
change/@fluentui-react-menu-c4c9135d-c4fa-4b44-a114-eb5c8c432139.json
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"type": "minor", | ||
"comment": "Add MenuList and MenuItem components", | ||
"packageName": "@fluentui/react-menu", | ||
"email": "lingfan.gao@microsoft.com", | ||
"dependentChangeType": "patch" | ||
} |
7 changes: 7 additions & 0 deletions
7
change/@fluentui-react-utils-b125c5c6-290a-4cde-bc2e-78094234bec7.json
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"type": "minor", | ||
"comment": "Add ObjectSlot type", | ||
"packageName": "@fluentui/react-utils", | ||
"email": "lingfan.gao@microsoft.com", | ||
"dependentChangeType": "patch" | ||
} |
51 changes: 51 additions & 0 deletions
51
packages/react-examples/src/react-menu/MenuList/MenuList.stories.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 |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import * as React from 'react'; | ||
|
||
import { MenuList, MenuItem } from '@fluentui/react-menu'; | ||
import { teamsLightTheme } from '@fluentui/react-theme'; | ||
import { FluentProvider } from '@fluentui/react-provider'; | ||
import { CutIcon, PasteIcon, EditIcon } from '@fluentui/react-icons-mdl2'; | ||
import { makeStyles } from '@fluentui/react-make-styles'; | ||
|
||
const useContainerStyles = makeStyles([ | ||
// This should eventually be the popup container styles | ||
[ | ||
null, | ||
theme => ({ | ||
backgroundColor: theme.alias.color.neutral.neutralBackground1, | ||
minWidth: '128px', | ||
minHeight: '48px', | ||
maxWidth: '128px', | ||
boxShadow: `${theme.alias.shadow.shadow16}`, | ||
paddingTop: '4px', | ||
paddingBottom: '4px', | ||
}), | ||
], | ||
]); | ||
const Container: React.FC = props => { | ||
const classNames = useContainerStyles({}); | ||
return <div className={classNames}>{props.children}</div>; | ||
}; | ||
|
||
export const MenuListExample = () => ( | ||
<FluentProvider theme={teamsLightTheme}> | ||
<Container> | ||
<MenuList> | ||
<MenuItem>Item</MenuItem> | ||
<MenuItem>Item</MenuItem> | ||
<MenuItem>Item</MenuItem> | ||
</MenuList> | ||
</Container> | ||
</FluentProvider> | ||
); | ||
|
||
export const MenuListWithIconsExample = () => ( | ||
<FluentProvider theme={teamsLightTheme}> | ||
<Container> | ||
<MenuList> | ||
<MenuItem icon={<CutIcon />}>Item</MenuItem> | ||
<MenuItem icon={<PasteIcon />}>Item</MenuItem> | ||
<MenuItem icon={<EditIcon />}>Item</MenuItem> | ||
</MenuList> | ||
</Container> | ||
</FluentProvider> | ||
); |
This file was deleted.
Oops, something went wrong.
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
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
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
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './components/MenuItem/index'; |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './components/MenuList/index'; |
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { isConformant as baseIsConformant, IsConformantOptions } from '@fluentui/react-conformance'; | ||
|
||
export function isConformant(testInfo: Omit<IsConformantOptions, 'componentPath'>) { | ||
const defaultOptions = { | ||
disabledTests: ['has-docblock'], | ||
componentPath: module!.parent!.filename.replace('.test', ''), | ||
}; | ||
|
||
baseIsConformant(defaultOptions, testInfo); | ||
} |
30 changes: 30 additions & 0 deletions
30
packages/react-menu/src/components/MenuItem/MenuItem.test.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 |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import * as React from 'react'; | ||
import { MenuItem } from './MenuItem'; | ||
import * as renderer from 'react-test-renderer'; | ||
import { ReactWrapper } from 'enzyme'; | ||
import { isConformant } from '../../common/isConformant'; | ||
|
||
describe('MenuItem', () => { | ||
isConformant({ | ||
Component: MenuItem, | ||
displayName: 'MenuItem', | ||
}); | ||
|
||
let wrapper: ReactWrapper | undefined; | ||
|
||
afterEach(() => { | ||
if (wrapper) { | ||
wrapper.unmount(); | ||
wrapper = undefined; | ||
} | ||
}); | ||
|
||
/** | ||
* Note: see more visual regression tests for MenuItem in /apps/vr-tests. | ||
*/ | ||
it('renders a default state', () => { | ||
const component = renderer.create(<MenuItem>Default MenuItem</MenuItem>); | ||
const tree = component.toJSON(); | ||
expect(tree).toMatchSnapshot(); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import * as React from 'react'; | ||
import { useMenuItem } from './useMenuItem'; | ||
import { MenuItemProps } from './MenuItem.types'; | ||
import { renderMenuItem } from './renderMenuItem'; | ||
import { useMenuItemStyles } from './useMenuItemStyles'; | ||
|
||
/** | ||
* Define a styled MenuItem, using the `useMenuItem` and `useMenuItemStyles` hook. | ||
* {@docCategory MenuItem} | ||
*/ | ||
export const MenuItem = React.forwardRef<HTMLElement, MenuItemProps>((props, ref) => { | ||
const state = useMenuItem(props, ref, { | ||
role: 'menuitem', | ||
tabIndex: 0, // TODO keyboard navigation | ||
}); | ||
|
||
useMenuItemStyles(state); | ||
return renderMenuItem(state); | ||
}); | ||
|
||
MenuItem.displayName = 'MenuItem'; |
20 changes: 20 additions & 0 deletions
20
packages/react-menu/src/components/MenuItem/MenuItem.types.ts
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import * as React from 'react'; | ||
import { ComponentProps, ShorthandProps, ObjectShorthandProps } from '@fluentui/react-utils'; | ||
|
||
export interface MenuItemProps extends ComponentProps, React.HTMLAttributes<HTMLElement> { | ||
/** | ||
* Icon slot rendered before children content | ||
*/ | ||
icon?: ShorthandProps; | ||
} | ||
|
||
export interface MenuItemState extends MenuItemProps { | ||
/** | ||
* Ref to the root slot | ||
*/ | ||
ref: React.MutableRefObject<HTMLElement>; | ||
/** | ||
* Icon slot when processed by internal state | ||
*/ | ||
icon?: ObjectShorthandProps<HTMLSpanElement>; | ||
} |
17 changes: 17 additions & 0 deletions
17
packages/react-menu/src/components/MenuItem/__snapshots__/MenuItem.test.tsx.snap
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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`MenuItem renders a default state 1`] = ` | ||
<div | ||
className="" | ||
icon={ | ||
Object { | ||
"as": "span", | ||
"className": "", | ||
} | ||
} | ||
role="menuitem" | ||
tabIndex={0} | ||
> | ||
Default MenuItem | ||
</div> | ||
`; |
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export * from './MenuItem'; | ||
export * from './MenuItem.types'; | ||
export * from './renderMenuItem'; | ||
export * from './useMenuItem'; | ||
export * from './useMenuItemStyles'; |
18 changes: 18 additions & 0 deletions
18
packages/react-menu/src/components/MenuItem/renderMenuItem.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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import * as React from 'react'; | ||
import { getSlots } from '@fluentui/react-utils'; | ||
import { MenuItemState } from './MenuItem.types'; | ||
import { menuItemShorthandProps } from './useMenuItem'; | ||
|
||
/** | ||
* Function that renders the final JSX of the component | ||
*/ | ||
export const renderMenuItem = (state: MenuItemState) => { | ||
const { slots, slotProps } = getSlots(state, menuItemShorthandProps); | ||
|
||
return ( | ||
<slots.root {...slotProps.root}> | ||
<slots.icon {...slotProps.icon} /> | ||
{state.children} | ||
</slots.root> | ||
); | ||
}; |
31 changes: 31 additions & 0 deletions
31
packages/react-menu/src/components/MenuItem/useMenuItem.ts
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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import * as React from 'react'; | ||
import { makeMergeProps, resolveShorthandProps } from '@fluentui/react-utils'; | ||
import { useMergedRefs } from '@fluentui/react-hooks'; | ||
import { MenuItemProps, MenuItemState } from './MenuItem.types'; | ||
|
||
/** | ||
* Consts listing which props are shorthand props. | ||
*/ | ||
export const menuItemShorthandProps = ['icon']; | ||
|
||
const mergeProps = makeMergeProps<MenuItemState>({ deepMerge: menuItemShorthandProps }); | ||
|
||
/** | ||
* Returns the props and state required to render the component | ||
*/ | ||
export const useMenuItem = ( | ||
props: MenuItemProps, | ||
ref: React.Ref<HTMLElement>, | ||
defaultProps?: MenuItemProps, | ||
): MenuItemState => { | ||
const state = mergeProps( | ||
{ | ||
ref: useMergedRefs(ref, React.useRef(null)), | ||
icon: { as: 'span' }, | ||
}, | ||
defaultProps, | ||
resolveShorthandProps(props, menuItemShorthandProps), | ||
); | ||
|
||
return state; | ||
}; |
55 changes: 55 additions & 0 deletions
55
packages/react-menu/src/components/MenuItem/useMenuItemStyles.ts
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 |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { makeStyles, ax } from '@fluentui/react-make-styles'; | ||
import { MenuItemState } from './MenuItem.types'; | ||
|
||
/** | ||
* Styles for the root slot | ||
*/ | ||
export const useRootStyles = makeStyles<MenuItemState>([ | ||
[ | ||
null, | ||
theme => ({ | ||
color: theme.alias.color.neutral.neutralForeground1, | ||
backgroundColor: theme.alias.color.neutral.neutralBackground1, | ||
paddingRight: '12px', | ||
paddingLeft: '12px', | ||
height: '32px', | ||
display: 'flex', | ||
alignItems: 'center', | ||
fontSize: theme.global.type.fontSizes.base[300], | ||
|
||
':hover': { | ||
backgroundColor: theme.alias.color.neutral.neutralBackground1Hover, | ||
}, | ||
|
||
':focus': { | ||
backgroundColor: theme.alias.color.neutral.neutralBackground1Hover, | ||
}, | ||
}), | ||
], | ||
]); | ||
|
||
/** | ||
* Styles for the icon slot | ||
*/ | ||
export const useIconStyles = makeStyles<MenuItemState>([ | ||
[ | ||
null, | ||
() => ({ | ||
width: '20px', | ||
height: '20px', | ||
marginRight: '9px', | ||
}), | ||
], | ||
]); | ||
|
||
/** Applies style classnames to slots */ | ||
export const useMenuItemStyles = (state: MenuItemState) => { | ||
const rootClassName = useRootStyles(state); | ||
const iconClassName = useIconStyles(state); | ||
|
||
state.className = ax(rootClassName, state.className); | ||
|
||
if (state.icon) { | ||
state.icon.className = ax(iconClassName, state.icon.className); | ||
} | ||
}; |
Oops, something went wrong.