-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
1,248 additions
and
99 deletions.
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
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
112 changes: 56 additions & 56 deletions
112
...ify/src/components/Item/actify.module.css → ...ctify/src/components/Item/item.module.css
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,56 +1,56 @@ | ||
.item { | ||
color: var(--md-sys-color-on-surface, #1d1b20); | ||
font-family: var( | ||
--md-sys-typescale-body-large-font, | ||
var(--md-ref-typeface-plain, Roboto) | ||
); | ||
font-size: var(--md-sys-typescale-body-large-size, 1rem); | ||
font-weight: var( | ||
--md-sys-typescale-body-large-weight, | ||
var(--md-ref-typeface-weight-regular, 400) | ||
); | ||
line-height: var(--md-sys-typescale-body-large-line-height, 1.5rem); | ||
align-items: center; | ||
box-sizing: border-box; | ||
display: flex; | ||
gap: 16px; | ||
min-height: 56px; | ||
overflow: hidden; | ||
padding: 12px 16px; | ||
position: relative; | ||
text-overflow: ellipsis; | ||
|
||
border-radius: inherit; | ||
flex: 1; | ||
color: var( | ||
--md-menu-item-label-text-color, | ||
var(--md-sys-color-on-surface, #1d1b20) | ||
); | ||
font-family: var( | ||
--md-menu-item-label-text-font, | ||
var( | ||
--md-sys-typescale-body-large-font, | ||
var(--md-ref-typeface-plain, Roboto) | ||
) | ||
); | ||
font-size: var( | ||
--md-menu-item-label-text-size, | ||
var(--md-sys-typescale-body-large-size, 1rem) | ||
); | ||
line-height: var( | ||
--md-menu-item-label-text-line-height, | ||
var(--md-sys-typescale-body-large-line-height, 1.5rem) | ||
); | ||
font-weight: var( | ||
--md-menu-item-label-text-weight, | ||
var( | ||
--md-sys-typescale-body-large-weight, | ||
var(--md-ref-typeface-weight-regular, 400) | ||
) | ||
); | ||
min-height: var(--md-menu-item-one-line-container-height, 56px); | ||
padding-top: var(--md-menu-item-top-space, 12px); | ||
padding-bottom: var(--md-menu-item-bottom-space, 12px); | ||
padding-inline-start: var(--md-menu-item-leading-space, 16px); | ||
padding-inline-end: var(--md-menu-item-trailing-space, 16px); | ||
} | ||
.item { | ||
color: var(--md-sys-color-on-surface, #1d1b20); | ||
font-family: var( | ||
--md-sys-typescale-body-large-font, | ||
var(--md-ref-typeface-plain, Roboto) | ||
); | ||
font-size: var(--md-sys-typescale-body-large-size, 1rem); | ||
font-weight: var( | ||
--md-sys-typescale-body-large-weight, | ||
var(--md-ref-typeface-weight-regular, 400) | ||
); | ||
line-height: var(--md-sys-typescale-body-large-line-height, 1.5rem); | ||
align-items: center; | ||
box-sizing: border-box; | ||
display: flex; | ||
gap: 16px; | ||
min-height: 56px; | ||
overflow: hidden; | ||
padding: 12px 16px; | ||
position: relative; | ||
text-overflow: ellipsis; | ||
|
||
border-radius: inherit; | ||
flex: 1; | ||
color: var( | ||
--md-menu-item-label-text-color, | ||
var(--md-sys-color-on-surface, #1d1b20) | ||
); | ||
font-family: var( | ||
--md-menu-item-label-text-font, | ||
var( | ||
--md-sys-typescale-body-large-font, | ||
var(--md-ref-typeface-plain, Roboto) | ||
) | ||
); | ||
font-size: var( | ||
--md-menu-item-label-text-size, | ||
var(--md-sys-typescale-body-large-size, 1rem) | ||
); | ||
line-height: var( | ||
--md-menu-item-label-text-line-height, | ||
var(--md-sys-typescale-body-large-line-height, 1.5rem) | ||
); | ||
font-weight: var( | ||
--md-menu-item-label-text-weight, | ||
var( | ||
--md-sys-typescale-body-large-weight, | ||
var(--md-ref-typeface-weight-regular, 400) | ||
) | ||
); | ||
min-height: var(--md-menu-item-one-line-container-height, 56px); | ||
padding-top: var(--md-menu-item-top-space, 12px); | ||
padding-bottom: var(--md-menu-item-bottom-space, 12px); | ||
padding-inline-start: var(--md-menu-item-leading-space, 16px); | ||
padding-inline-end: var(--md-menu-item-trailing-space, 16px); | ||
} |
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,98 @@ | ||
import { AriaButtonProps, Placement, useMenu, useMenuTrigger } from 'react-aria' | ||
import type { AriaMenuProps, MenuTriggerProps } from '@react-types/menu' | ||
import { useMenuTriggerState, useTreeState } from 'react-stately' | ||
|
||
import { Button } from './../Button' | ||
import { MenuItem } from './MenuItem' | ||
import { MenuItems } from './MenuItems' | ||
import { Popover } from './../Popover' | ||
import React from 'react' | ||
import clsx from 'clsx' | ||
import styles from './menu.module.css' | ||
|
||
interface MenuButtonProps<T extends object> | ||
extends AriaMenuProps<T>, | ||
MenuTriggerProps { | ||
style?: React.CSSProperties | ||
className?: string | ||
label?: string | ||
placement?: Placement | ||
activator?: ( | ||
ref: React.RefObject<null>, | ||
menuTriggerProps: AriaButtonProps<'button'> | ||
) => React.JSX.Element | ||
} | ||
|
||
export function Menu<T extends object>(props: MenuButtonProps<T>) { | ||
// Create state based on the incoming props | ||
const state = useMenuTriggerState(props) | ||
|
||
// Get props for the menu trigger and menu elements | ||
const ref = React.useRef(null) | ||
const { menuTriggerProps, menuProps } = useMenuTrigger<T>({}, state, ref) | ||
|
||
return ( | ||
<> | ||
{props.label && ( | ||
<Button {...menuTriggerProps} ref={ref}> | ||
{props.label} | ||
</Button> | ||
)} | ||
{props?.activator?.(ref, menuTriggerProps)} | ||
{state.isOpen && ( | ||
<Popover state={state} triggerRef={ref} placement={props.placement}> | ||
<MenuRoot | ||
{...props} | ||
{...menuProps} | ||
autoFocus={state.focusStrategy || true} | ||
onClose={() => state.close()} | ||
/> | ||
</Popover> | ||
)} | ||
</> | ||
) | ||
} | ||
|
||
interface MenuProps<T extends object> extends AriaMenuProps<T> { | ||
onClose: () => void | ||
style?: React.CSSProperties | ||
className?: string | ||
} | ||
|
||
function MenuRoot<T extends object>(props: MenuProps<T>) { | ||
// Create state based on the incoming props | ||
const state = useTreeState(props) | ||
|
||
// Get props for the menu element | ||
const ref = React.useRef(null) | ||
const { menuProps } = useMenu(props, state, ref) | ||
|
||
return ( | ||
<ul | ||
ref={ref} | ||
{...menuProps} | ||
style={props.style} | ||
className={clsx(styles['menu-item'], props.className)} | ||
> | ||
{[...state.collection].map((item) => | ||
item.type == 'section' ? ( | ||
<MenuItems | ||
key={item.key} | ||
section={item} | ||
state={state} | ||
onClose={props.onClose} | ||
onAction={() => props.onAction} | ||
/> | ||
) : ( | ||
<MenuItem | ||
key={item.key} | ||
item={item} | ||
state={state} | ||
onClose={props.onClose} | ||
onAction={() => props.onAction} | ||
/> | ||
) | ||
)} | ||
</ul> | ||
) | ||
} |
Oops, something went wrong.