From 5b4d900b90f1531c04747171be608e763ee865d8 Mon Sep 17 00:00:00 2001 From: Mikyo King Date: Tue, 1 Oct 2024 11:53:43 -0600 Subject: [PATCH] feat: add compact picker --- src/card/Card.tsx | 2 +- src/dropdown/DropdownButton.tsx | 68 ++++++++++++++++++++++++--------- src/picker/Picker.tsx | 2 + src/types/button.ts | 9 +---- src/types/index.ts | 1 + src/types/select.ts | 5 ++- src/types/sizing.ts | 7 ++++ stories/Picker.stories.tsx | 42 ++++++++++++++++++++ 8 files changed, 107 insertions(+), 29 deletions(-) create mode 100644 src/types/sizing.ts diff --git a/src/card/Card.tsx b/src/card/Card.tsx index 832606f1..3644b376 100644 --- a/src/card/Card.tsx +++ b/src/card/Card.tsx @@ -39,7 +39,7 @@ const bodyCSS = css` `; export interface CardBaseProps { - title?: string; + title?: ReactNode; subTitle?: string; variant?: CardVariant; children: ReactNode; diff --git a/src/dropdown/DropdownButton.tsx b/src/dropdown/DropdownButton.tsx index d09c7b94..2a23d04e 100644 --- a/src/dropdown/DropdownButton.tsx +++ b/src/dropdown/DropdownButton.tsx @@ -5,7 +5,7 @@ import { useButton } from '@react-aria/button'; import { useHover } from '@react-aria/interactions'; import { FocusRing } from '@react-aria/focus'; import { classNames } from '../utils/classNames'; -import { FocusableRef, Validation } from '../types'; +import { FocusableRef, SizingProps, Validation } from '../types'; import { useFocusableRef } from '../utils/useDOMRef'; import theme from '../theme'; import { AddonBefore } from '../field'; @@ -17,7 +17,10 @@ const appearKeyframes = keyframes` 0% { opacity: 0; } 100% { opacity: 1; } `; -export interface DropdownButtonProps extends AddonableProps, Validation { +export interface DropdownButtonProps + extends AddonableProps, + Validation, + SizingProps { /** * Whether the button should be displayed with a quiet style. * @default false @@ -54,10 +57,7 @@ const buttonBaseCSS = css` color: var(--ac-field-text-color-override, var(--ac-global-text-color-900)); } .ac-dropdown-button__dropdown-icon { - margin: 10px 0 10px 10px; flex: fixed; - width: 16px; - height: 16px; font-size: 16px; } @@ -92,6 +92,37 @@ const buttonBaseCSS = css` &.ac-dropdown-button--invalid > .ac-dropdown-button__text { padding-right: 0; } + + // Sizing + &.ac-dropdown-button--default { + .ac-dropdown-button__text { + margin: var(--ac-global-dimension-static-size-100) + var(--ac-global-dimension-static-size-100) + var(--ac-global-dimension-static-size-100) + var(--ac-global-dimension-static-size-200); + } + .ac-dropdown-button__dropdown-icon { + margin: 10px 0 10px 10px; + flex: fixed; + width: 16px; + height: 16px; + } + } + &.ac-dropdown-button--compact { + .ac-dropdown-button__text { + margin: var(--ac-global-dimension-static-size-50) + var(--ac-global-dimension-static-size-50) + var(--ac-global-dimension-static-size-50) + var(--ac-global-dimension-static-size-100); + } + .ac-dropdown-button__dropdown-icon { + margin: var(--ac-global-dimension-size-50) 0 + var(--ac-global-dimension-size-50) var(--ac-global-dimension-size-50); + flex: fixed; + width: 16px; + height: 16px; + } + } `; /** @@ -155,12 +186,6 @@ const nonQuietButtonCSS = css` cursor: default; border: 1px solid ${theme.components.dropdown.borderColor}; } - .ac-dropdown-button__text { - margin: var(--ac-global-dimension-static-size-100) - var(--ac-global-dimension-static-size-100) - var(--ac-global-dimension-static-size-100) - var(--ac-global-dimension-static-size-200); - } &.ac-dropdown-button--invalid { border: 1px solid var(--ac-global-color-danger); @@ -194,6 +219,7 @@ function DropdownButton( style, addonBefore, validationState, + size = 'default', // TODO: add support for autoFocus // autoFocus, ...otherProps @@ -214,14 +240,18 @@ function DropdownButton( + + + setFrequency(selected as string)} + > + Rarely + Sometimes + Always + + + + + + ); +}; + // By passing using the Args format for exported stories, you can control the props for a component for reuse in a test // https://storybook.js.org/docs/react/workflows/unit-testing export const controlled = Controlled.bind({});