|
| 1 | +import { CheckIcon as LucideCheckIcon } from 'lucide-react'; |
| 2 | +import { Menu as BaseMenu } from '@base-ui-components/react/menu'; |
| 3 | +import { css, styled, t } from '@pigment-css/react-new'; |
| 4 | + |
| 5 | +import { spacing } from 'docs/utils/theme'; |
| 6 | + |
| 7 | +const Trigger = styled(BaseMenu.Trigger)` |
| 8 | + box-sizing: border-box; |
| 9 | + display: flex; |
| 10 | + align-items: center; |
| 11 | + justify-content: center; |
| 12 | + gap: 0.375rem; |
| 13 | + height: 2.5rem; |
| 14 | + padding: 0 0.5rem; |
| 15 | + margin: 0; |
| 16 | + outline: 0; |
| 17 | + border-radius: 0.375rem; |
| 18 | + font-family: inherit; |
| 19 | + font-size: 1rem; |
| 20 | + font-weight: 500; |
| 21 | + line-height: 1.5rem; |
| 22 | + color: ${t('$color.gray.900')}; |
| 23 | + user-select: none; |
| 24 | +
|
| 25 | + @media (hover: hover) { |
| 26 | + &:hover { |
| 27 | + background-color: ${t('$color.gray.100')}; |
| 28 | + } |
| 29 | + } |
| 30 | +
|
| 31 | + &:active { |
| 32 | + background-color: ${t('$color.gray.100')}; |
| 33 | + } |
| 34 | +
|
| 35 | + &[data-popup-open] { |
| 36 | + background-color: ${t('$color.gray.100')}; |
| 37 | + } |
| 38 | +
|
| 39 | + &:focus-visible { |
| 40 | + outline: 2px solid ${t('$color.blue')}; |
| 41 | + outline-offset: -1px; |
| 42 | + } |
| 43 | +`; |
| 44 | + |
| 45 | +const Positioner = styled(BaseMenu.Positioner)` |
| 46 | + outline: 0; |
| 47 | +`; |
| 48 | + |
| 49 | +const Popup = styled(BaseMenu.Popup)` |
| 50 | + box-sizing: border-box; |
| 51 | + padding-block: 0.25rem; |
| 52 | + border-radius: 0.375rem; |
| 53 | + background-color: canvas; |
| 54 | + color: ${t('$color.gray.900')}; |
| 55 | + transform-origin: var(--transform-origin); |
| 56 | + transition: |
| 57 | + transform 150ms, |
| 58 | + opacity 150ms; |
| 59 | +
|
| 60 | + &[data-starting-style], |
| 61 | + &[data-ending-style] { |
| 62 | + opacity: 0; |
| 63 | + transform: scale(0.9); |
| 64 | + } |
| 65 | +
|
| 66 | + @media (prefers-color-scheme: light) { |
| 67 | + outline: 1px solid ${t('$color.gray.200')}; |
| 68 | + box-shadow: |
| 69 | + 0 10px 15px -3px ${t('$color.gray.200')}, |
| 70 | + 0 4px 6px -4px ${t('$color.gray.200')}; |
| 71 | + } |
| 72 | +
|
| 73 | + @media (prefers-color-scheme: dark) { |
| 74 | + outline: 1px solid ${t('$color.gray.300')}; |
| 75 | + outline-offset: -1px; |
| 76 | + } |
| 77 | +`; |
| 78 | + |
| 79 | +const Arrow = styled(BaseMenu.Arrow)` |
| 80 | + display: flex; |
| 81 | +
|
| 82 | + &[data-side='top'] { |
| 83 | + bottom: -8px; |
| 84 | + rotate: 180deg; |
| 85 | + } |
| 86 | +
|
| 87 | + &[data-side='bottom'] { |
| 88 | + top: -8px; |
| 89 | + rotate: 0deg; |
| 90 | + } |
| 91 | +
|
| 92 | + &[data-side='left'] { |
| 93 | + right: -13px; |
| 94 | + rotate: 90deg; |
| 95 | + } |
| 96 | +
|
| 97 | + &[data-side='right'] { |
| 98 | + left: -13px; |
| 99 | + rotate: -90deg; |
| 100 | + } |
| 101 | +`; |
| 102 | + |
| 103 | +export const CheckIcon = styled(LucideCheckIcon)` |
| 104 | + stroke: ${t('$color.green')}; |
| 105 | +`; |
| 106 | + |
| 107 | +export const RadioItem = styled(BaseMenu.RadioItem)` |
| 108 | + display: flex; |
| 109 | + align-items: center; |
| 110 | + gap: 0.25rem; |
| 111 | + outline: 0; |
| 112 | + cursor: default; |
| 113 | + user-select: none; |
| 114 | + padding-block: 0.5rem; |
| 115 | + padding-inline: 1rem; |
| 116 | + font-size: 0.875rem; |
| 117 | + line-height: 1rem; |
| 118 | +
|
| 119 | + &[data-highlighted] { |
| 120 | + z-index: 0; |
| 121 | + position: relative; |
| 122 | + color: ${t('$color.gray.50')}; |
| 123 | +
|
| 124 | + ${CheckIcon} { |
| 125 | + stroke: ${t('$color.background')}; |
| 126 | + } |
| 127 | + } |
| 128 | +
|
| 129 | + &[data-highlighted]::before { |
| 130 | + content: ''; |
| 131 | + z-index: -1; |
| 132 | + position: absolute; |
| 133 | + inset-block: 0; |
| 134 | + inset-inline: 0.25rem; |
| 135 | + border-radius: 0.25rem; |
| 136 | + background-color: ${t('$color.gray.900')}; |
| 137 | + } |
| 138 | +`; |
| 139 | + |
| 140 | +export const triggerIcon = css(({ theme }) => ({ |
| 141 | + marginRight: spacing(theme, -0.25), |
| 142 | +})); |
| 143 | + |
| 144 | +export const arrowIconCls = { |
| 145 | + fill: css` |
| 146 | + fill: canvas; |
| 147 | + `, |
| 148 | + outerStroke: css` |
| 149 | + @media (prefers-color-scheme: light) { |
| 150 | + fill: var(--color-gray-200); |
| 151 | + } |
| 152 | + `, |
| 153 | + innerStroke: css` |
| 154 | + @media (prefers-color-scheme: dark) { |
| 155 | + fill: var(--color-gray-300); |
| 156 | + } |
| 157 | + `, |
| 158 | +}; |
| 159 | + |
| 160 | +export const Menu = { |
| 161 | + ...BaseMenu, |
| 162 | + Trigger, |
| 163 | + Positioner, |
| 164 | + Popup, |
| 165 | + Arrow, |
| 166 | + RadioItem, |
| 167 | +}; |
0 commit comments