From 7d8efaaff7e04c2f2978e48ff711136cc0f2b078 Mon Sep 17 00:00:00 2001 From: Angie Che Date: Sun, 22 Nov 2026 15:51:04 -0500 Subject: [PATCH 1/4] Add Button and Filter components on Chakra (#94) --- apps/frontend/src/app.tsx | 8 +- .../src/components/Button/Button.spec.tsx | 145 ++++++++++ .../frontend/src/components/Button/Button.tsx | 126 +++++++++ apps/frontend/src/components/Button/index.ts | 3 + .../src/components/Button/variants.ts | 123 ++++++++ .../src/components/Filter/Filter.spec.tsx | 139 +++++++++ .../frontend/src/components/Filter/Filter.tsx | 153 ++++++++++ apps/frontend/src/components/Filter/index.ts | 1 + .../src/components/icons/ButtonIcons.tsx | 167 +++++++++++ apps/frontend/src/components/index.ts | 2 + .../containers/buttons-filters-preview.tsx | 265 ++++++++++++++++++ apps/frontend/src/containers/mockFilters.ts | 69 +++++ 12 files changed, 1200 insertions(+), 1 deletion(-) create mode 100644 apps/frontend/src/components/Button/Button.spec.tsx create mode 100644 apps/frontend/src/components/Button/Button.tsx create mode 100644 apps/frontend/src/components/Button/index.ts create mode 100644 apps/frontend/src/components/Button/variants.ts create mode 100644 apps/frontend/src/components/Filter/Filter.spec.tsx create mode 100644 apps/frontend/src/components/Filter/Filter.tsx create mode 100644 apps/frontend/src/components/Filter/index.ts create mode 100644 apps/frontend/src/components/icons/ButtonIcons.tsx create mode 100644 apps/frontend/src/components/index.ts create mode 100644 apps/frontend/src/containers/buttons-filters-preview.tsx create mode 100644 apps/frontend/src/containers/mockFilters.ts diff --git a/apps/frontend/src/app.tsx b/apps/frontend/src/app.tsx index 32b783df2..f1c6e5435 100644 --- a/apps/frontend/src/app.tsx +++ b/apps/frontend/src/app.tsx @@ -4,6 +4,7 @@ import Root from '@containers/root'; import NotFound from '@containers/404'; import Test from '@containers/test'; import Design from '@containers/design'; +import ButtonsFiltersPreview from '@containers/buttons-filters-preview'; import { Providers } from './providers'; const router = createBrowserRouter([ @@ -16,7 +17,12 @@ const router = createBrowserRouter([ path: '/test', element: , }, - ...(import.meta.env.DEV ? [{ path: '/design', element: }] : []), + ...(import.meta.env.DEV + ? [ + { path: '/design', element: }, + { path: '/dev/buttons', element: }, + ] + : []), ]); export const App: React.FC = () => { diff --git a/apps/frontend/src/components/Button/Button.spec.tsx b/apps/frontend/src/components/Button/Button.spec.tsx new file mode 100644 index 000000000..e89f44cbc --- /dev/null +++ b/apps/frontend/src/components/Button/Button.spec.tsx @@ -0,0 +1,145 @@ +import { fireEvent, screen } from '@testing-library/react'; +import { describe, expect, it, vi } from 'vitest'; +import { renderWithProviders } from '../../test/render'; +import { Button } from './Button'; +import { BUTTON_VARIANTS, type ButtonVariant } from './variants'; + +const VARIANTS = Object.keys(BUTTON_VARIANTS) as ButtonVariant[]; + +describe('Button', () => { + it.each(VARIANTS)('renders the label for variant "%s"', (variant) => { + renderWithProviders(); + expect(screen.getByRole('button', { name: 'Label' })).toBeTruthy(); + }); + + it('defaults to the primary variant and md size', () => { + renderWithProviders(); + const button = screen.getByRole('button', { name: 'Upload' }); + expect(button.getAttribute('data-variant')).toBe('primary'); + expect(button.getAttribute('data-size')).toBe('md'); + }); + + it('calls onClick when clicked', () => { + const onClick = vi.fn(); + renderWithProviders(); + fireEvent.click(screen.getByRole('button', { name: 'Go' })); + expect(onClick).toHaveBeenCalledTimes(1); + }); + + it('does not call onClick when disabled', () => { + const onClick = vi.fn(); + renderWithProviders( + , + ); + const button = screen.getByRole('button', { name: 'Go' }); + expect(button).toHaveProperty('disabled', true); + fireEvent.click(button); + expect(onClick).not.toHaveBeenCalled(); + }); + + it('is disabled, busy and ignores clicks while loading', () => { + const onClick = vi.fn(); + renderWithProviders( + , + ); + const button = screen.getByRole('button'); + expect(button).toHaveProperty('disabled', true); + expect(button.getAttribute('aria-busy')).toBe('true'); + fireEvent.click(button); + expect(onClick).not.toHaveBeenCalled(); + }); + + it('shows loadingText while loading', () => { + renderWithProviders( + , + ); + expect(screen.getByText('Submitting')).toBeTruthy(); + }); + + it('is not busy when not loading', () => { + renderWithProviders(); + expect(screen.getByRole('button').getAttribute('aria-busy')).not.toBe( + 'true', + ); + }); + + it('renders leftIcon and rightIcon, hidden from assistive tech', () => { + renderWithProviders( + , + ); + const left = screen.getByTestId('left'); + const right = screen.getByTestId('right'); + expect(left.closest('[aria-hidden="true"]')).not.toBeNull(); + expect(right.closest('[aria-hidden="true"]')).not.toBeNull(); + // The icons don't change the accessible name. + expect(screen.getByRole('button', { name: 'Source: All' })).toBeTruthy(); + }); + + it('is reachable by aria-label when icon-only', () => { + renderWithProviders( + ); + expect(screen.getByRole('button', { name: 'A' }).getAttribute('type')).toBe( + 'button', + ); + unmount(); + renderWithProviders(); + expect(screen.getByRole('button', { name: 'B' }).getAttribute('type')).toBe( + 'submit', + ); + }); + + it('renders a real link when href is given', () => { + renderWithProviders( + , + ); + const link = screen.getByRole('link', { name: 'Today’s Entry' }); + expect(link.tagName).toBe('A'); + expect(link.getAttribute('href')).toBe('/entry/today'); + expect(screen.queryByRole('button')).toBeNull(); + }); + + it('adds rel for links that open in a new tab', () => { + renderWithProviders( + , + ); + expect(screen.getByRole('link', { name: 'Docs' }).getAttribute('rel')).toBe( + 'noopener noreferrer', + ); + }); + + it('works as the child of asChild with a custom link', () => { + renderWithProviders( + , + ); + const link = screen.getByRole('link', { name: 'Custom' }); + expect(link.getAttribute('href')).toBe('/x'); + expect(link.hasAttribute('type')).toBe(false); + }); +}); diff --git a/apps/frontend/src/components/Button/Button.tsx b/apps/frontend/src/components/Button/Button.tsx new file mode 100644 index 000000000..94d400227 --- /dev/null +++ b/apps/frontend/src/components/Button/Button.tsx @@ -0,0 +1,126 @@ +import { + Button as ChakraButton, + type ButtonProps as ChakraButtonProps, +} from '@chakra-ui/react'; +import type { ReactNode } from 'react'; +import { + BUTTON_SIZES, + BUTTON_VARIANTS, + type ButtonSize, + type ButtonVariant, +} from './variants'; + +type BaseProps = Omit< + ChakraButtonProps, + 'variant' | 'size' | 'loading' | 'loadingText' | 'children' +> & { + /** Look of the button. Label and icons are passed by the caller. */ + variant?: ButtonVariant; + /** `md` is Figma's 40px. `sm` is a compact option (not in Figma). */ + size?: ButtonSize; + leftIcon?: ReactNode; + rightIcon?: ReactNode; + /** Shows a spinner, disables the button and keeps its width. */ + loading?: boolean; + loadingText?: ReactNode; + /** Renders a real `` styled as the button (use for navigation). */ + href?: string; + target?: string; + rel?: string; +}; + +// With no children the button is icon-only and needs an accessible name. +export type ButtonProps = BaseProps & + ({ children: ReactNode } | { children?: undefined; 'aria-label': string }); + +const Icon = ({ children }: { children: ReactNode }) => ( + +); + +/** + * Chakra's Button dressed with the Figma "Buttons" frame (156:1559), using the + * tokens from `styles/tokens.css`. Chakra props such as `onClick`, `disabled`, + * `asChild` and `aria-*` pass through. `type` defaults to "button" so a button + * in a form never submits by accident. + */ +export function Button({ + variant = 'primary', + size = 'md', + leftIcon, + rightIcon, + loading = false, + loadingText, + href, + target, + rel, + type, + asChild, + children, + ...rest +}: ButtonProps) { + const styles = { ...BUTTON_VARIANTS[variant], ...BUTTON_SIZES[size] }; + // `link` and `ghost` own their height, whatever the size. + if (variant === 'link') styles.h = 'auto'; + if (variant === 'ghost') styles.h = BUTTON_VARIANTS.ghost.h; + + const common = { + ...styles, + 'data-variant': variant, + 'data-size': size, + ...rest, + }; + + const content = ( + <> + {leftIcon ? {leftIcon} : null} + {children} + {rightIcon ? {rightIcon} : null} + + ); + + if (href) { + return ( + + + {content} + + + ); + } + + if (asChild) { + // The caller supplies the element (e.g. a router Link), so don't add + // `type` or wrap its content. + return ( + + {children} + + ); + } + + return ( + + {content} + + ); +} diff --git a/apps/frontend/src/components/Button/index.ts b/apps/frontend/src/components/Button/index.ts new file mode 100644 index 000000000..123ccf573 --- /dev/null +++ b/apps/frontend/src/components/Button/index.ts @@ -0,0 +1,3 @@ +export * from './Button'; +export { BUTTON_VARIANTS } from './variants'; +export type { ButtonVariant, ButtonSize } from './variants'; diff --git a/apps/frontend/src/components/Button/variants.ts b/apps/frontend/src/components/Button/variants.ts new file mode 100644 index 000000000..b918ee8f3 --- /dev/null +++ b/apps/frontend/src/components/Button/variants.ts @@ -0,0 +1,123 @@ +import type { ButtonProps as ChakraButtonProps } from '@chakra-ui/react'; + +export type ButtonVariant = 'primary' | 'secondary' | 'dark' | 'link' | 'ghost'; +export type ButtonSize = 'sm' | 'md'; + +// Values with no token in #68's tokens.css yet. They are named here and listed +// in the PR instead of being scattered through the styles. Where #76 already +// adds a token (`--radius-xxs`, `--color-primary-hover`) we read it and fall +// back to the Figma value so this works before and after that merges. +const RADIUS = 'var(--radius-xxs, 4px)'; // Figma radii/l2 +const PRIMARY_HOVER = 'var(--color-primary-hover, var(--sea-green-400))'; // Figma "Clicked" +const FOCUS_RING = 'var(--sea-green-600)'; // no Figma design, assumption +const HEIGHT_MD = '40px'; // Figma Size/10 +const HEIGHT_SM = '32px'; // assumption, not in Figma + +type StyleProps = Partial; + +const base = { + gap: 'var(--space-2)', + px: 'var(--space-4)', + py: '2px', + minW: '40px', + borderRadius: RADIUS, + borderWidth: '1px', + borderStyle: 'solid', + // Figma uses Inter 14/500; Inter isn't loaded in the app (flagged in PR), + // so this uses the body font. + fontFamily: 'var(--font-body)', + fontSize: '0.875rem', + fontWeight: 500, + lineHeight: '20px', + textDecoration: 'none', + cursor: 'pointer', + transition: 'background-color 120ms, border-color 120ms, color 120ms', + _focusVisible: { + outline: `2px solid ${FOCUS_RING}`, + outlineOffset: '2px', + }, + _disabled: { + opacity: 0.5, + cursor: 'not-allowed', + }, +} satisfies StyleProps; + +/** Style per variant. Callers pass the label and icons, so there is one + * variant per look, not one per label (Submit, Cancel, Download, ...). */ +export const BUTTON_VARIANTS: Record = { + // Upload, Re-Upload, Refresh, Download, Submit, Add Text, Source: All + primary: { + ...base, + bg: 'var(--color-primary)', + borderColor: 'var(--color-primary)', + color: 'var(--color-text-inverse)', + _hover: { bg: PRIMARY_HOVER, borderColor: PRIMARY_HOVER }, + // Pressed state is an assumption (--sea-green-600 is in the variables + // but not in the frames). + _active: { + bg: 'var(--sea-green-600)', + borderColor: 'var(--sea-green-600)', + }, + }, + // Cancel, Close. Figma's border is 1.5px. + secondary: { + ...base, + bg: 'var(--color-bg-card)', + borderWidth: '1.5px', + borderColor: 'var(--color-border)', + color: 'var(--color-text)', + _hover: { bg: 'var(--deep-blue-50)' }, + _active: { bg: 'var(--deep-blue-100)' }, + }, + // Clear Filters + dark: { + ...base, + bg: 'var(--deep-blue-400)', + borderColor: 'var(--deep-blue-400)', + color: 'var(--color-text-inverse)', + _hover: { + bg: 'var(--deep-blue-300)', + borderColor: 'var(--deep-blue-300)', + }, + _active: { + bg: 'var(--deep-blue-500)', + borderColor: 'var(--deep-blue-500)', + }, + }, + // Today's Entry: Arial bold 14/24 underlined text, green when "Clicked". + link: { + ...base, + h: 'auto', + minW: 0, + p: 0, + borderWidth: 0, + borderRadius: '2px', + bg: 'transparent', + color: 'var(--color-text)', + fontWeight: 700, + lineHeight: '24px', + textDecoration: 'underline', + _hover: { color: 'var(--sea-green-600)', bg: 'transparent' }, + _active: { color: 'var(--sea-green-600)', bg: 'transparent' }, + }, + // Open: green chevron only, no background. + ghost: { + ...base, + h: '32px', + minW: '32px', + px: '4px', + py: '5px', + borderWidth: 0, + borderRadius: '20px', + bg: 'transparent', + color: 'var(--color-primary)', + _hover: { bg: 'var(--deep-blue-50)' }, + _active: { bg: 'var(--deep-blue-100)' }, + }, +}; + +/** Height per size. `link` and `ghost` keep their own height. */ +export const BUTTON_SIZES: Record = { + md: { h: HEIGHT_MD }, + sm: { h: HEIGHT_SM, px: 'var(--space-3)' }, +}; diff --git a/apps/frontend/src/components/Filter/Filter.spec.tsx b/apps/frontend/src/components/Filter/Filter.spec.tsx new file mode 100644 index 000000000..f811b5114 --- /dev/null +++ b/apps/frontend/src/components/Filter/Filter.spec.tsx @@ -0,0 +1,139 @@ +import { screen, waitFor } from '@testing-library/react'; +import userEvent from '@testing-library/user-event'; +import { useState } from 'react'; +import { describe, expect, it, vi } from 'vitest'; +import { renderWithProviders } from '../../test/render'; +import { Filter, type FilterOption } from './Filter'; + +const OPTIONS: FilterOption[] = [ + { value: 'all', label: 'All uploaders' }, + { value: 'intern', label: 'Intern' }, + { value: 'admin', label: 'Admin' }, +]; + +const trigger = () => screen.getByRole('combobox'); + +function Controlled({ + onChange = () => undefined, + initial = 'all', + ...rest +}: { + onChange?: (value: string) => void; + initial?: string; + disabled?: boolean; + icon?: React.ReactNode; + placeholder?: string; +}) { + const [value, setValue] = useState(initial); + return ( + { + setValue(v); + onChange(v); + }} + {...rest} + /> + ); +} + +describe('Filter', () => { + it('shows the label and the label of the current value', () => { + renderWithProviders(); + expect(screen.getByText('Uploaded by')).toBeTruthy(); + expect(trigger().textContent).toContain('Intern'); + }); + + it('wires the label to the trigger', () => { + renderWithProviders(); + expect(screen.getByRole('combobox', { name: /Uploaded by/ })).toBeTruthy(); + }); + + it('shows the placeholder when the value matches no option', () => { + renderWithProviders(); + expect(trigger().textContent).toContain('Pick one'); + }); + + it('opens the options when the trigger is clicked', async () => { + const user = userEvent.setup(); + renderWithProviders(); + expect(trigger().getAttribute('aria-expanded')).toBe('false'); + await user.click(trigger()); + expect(trigger().getAttribute('aria-expanded')).toBe('true'); + expect(await screen.findAllByRole('option')).toHaveLength(3); + }); + + it('marks the current option as selected', async () => { + const user = userEvent.setup(); + renderWithProviders(); + await user.click(trigger()); + const intern = await screen.findByRole('option', { name: 'Intern' }); + expect(intern.getAttribute('aria-selected')).toBe('true'); + expect( + screen + .getByRole('option', { name: 'Admin' }) + .getAttribute('aria-selected'), + ).toBe('false'); + }); + + it('calls onChange with the value and closes when an option is picked', async () => { + const user = userEvent.setup(); + const onChange = vi.fn(); + renderWithProviders(); + await user.click(trigger()); + await user.click(await screen.findByRole('option', { name: 'Admin' })); + expect(onChange).toHaveBeenCalledWith('admin'); + await waitFor(() => + expect(trigger().getAttribute('aria-expanded')).toBe('false'), + ); + expect(trigger().textContent).toContain('Admin'); + }); + + it('opens with Enter and selects with arrows + Enter', async () => { + const user = userEvent.setup(); + const onChange = vi.fn(); + renderWithProviders(); + trigger().focus(); + + await user.keyboard('{Enter}'); + expect(trigger().getAttribute('aria-expanded')).toBe('true'); + await screen.findAllByRole('option'); + + await user.keyboard('{ArrowDown}{Enter}'); + expect(onChange).toHaveBeenCalledTimes(1); + await waitFor(() => + expect(trigger().getAttribute('aria-expanded')).toBe('false'), + ); + }); + + it('opens with ArrowDown and closes with Escape', async () => { + const user = userEvent.setup(); + renderWithProviders(); + trigger().focus(); + + await user.keyboard('{ArrowDown}'); + expect(trigger().getAttribute('aria-expanded')).toBe('true'); + await screen.findAllByRole('option'); + + await user.keyboard('{Escape}'); + await waitFor(() => + expect(trigger().getAttribute('aria-expanded')).toBe('false'), + ); + }); + + it('cannot be opened when disabled', async () => { + const user = userEvent.setup(); + renderWithProviders(); + expect(trigger().hasAttribute('disabled')).toBe(true); + await user.click(trigger()); + expect(trigger().getAttribute('aria-expanded')).toBe('false'); + expect(screen.queryAllByRole('option')).toHaveLength(0); + }); + + it('renders the leading icon', () => { + renderWithProviders(} />); + expect(screen.getByTestId('calendar')).toBeTruthy(); + }); +}); diff --git a/apps/frontend/src/components/Filter/Filter.tsx b/apps/frontend/src/components/Filter/Filter.tsx new file mode 100644 index 000000000..b693c8f10 --- /dev/null +++ b/apps/frontend/src/components/Filter/Filter.tsx @@ -0,0 +1,153 @@ +import { Select, createListCollection } from '@chakra-ui/react'; +import { useMemo } from 'react'; +import { FilterChevronIcon } from '../icons/ButtonIcons'; + +export interface FilterOption { + value: string; + label: string; +} + +export interface FilterProps { + /** Visible label above the trigger ("Date range", "Uploaded by"). */ + label?: string; + options: FilterOption[]; + /** Controlled value. */ + value: string; + onChange: (value: string) => void; + /** Shown when `value` matches no option. */ + placeholder?: string; + /** Leading icon, e.g. the calendar on the date filter. Decorative. */ + icon?: React.ReactNode; + /** `md` is Figma's 54px. `sm` is a compact option (not in Figma). */ + size?: 'sm' | 'md'; + disabled?: boolean; + /** Figma widths differ per filter (date ~442px, uploader ~346px). */ + width?: string | number; +} + +// Not in tokens.css yet, listed in the PR: Figma's filter height (54px) and +// its compact size (assumption), and the 12/14px padding. +const HEIGHT = { md: '54px', sm: '40px' } as const; + +/** + * Dropdown filter from the Figma "Filter" frame (528:7117), built on Chakra's + * accessible `Select`. Controlled: it shows the current value and reports the + * picked one. Keyboard support (Enter/Space/Arrows, Escape) comes from Chakra. + */ +export function Filter({ + label, + options, + value, + onChange, + placeholder, + icon, + size = 'md', + disabled = false, + width, +}: FilterProps) { + const collection = useMemo( + () => createListCollection({ items: options }), + [options], + ); + const current = options.some((o) => o.value === value) ? [value] : []; + + return ( + { + if (e.value[0] !== undefined) onChange(e.value[0]); + }} + disabled={disabled} + positioning={{ sameWidth: true }} + width={width ?? 'auto'} + minW={0} + gap="var(--space-2)" + > + + {label ? ( + + {label} + + ) : null} + + + {icon ? ( + + ) : null} + + + + + + + {collection.items.map((item) => ( + + {item.label} + + + ))} + + + + ); +} diff --git a/apps/frontend/src/components/Filter/index.ts b/apps/frontend/src/components/Filter/index.ts new file mode 100644 index 000000000..0eea77907 --- /dev/null +++ b/apps/frontend/src/components/Filter/index.ts @@ -0,0 +1 @@ +export * from './Filter'; diff --git a/apps/frontend/src/components/icons/ButtonIcons.tsx b/apps/frontend/src/components/icons/ButtonIcons.tsx new file mode 100644 index 000000000..d1e36245c --- /dev/null +++ b/apps/frontend/src/components/icons/ButtonIcons.tsx @@ -0,0 +1,167 @@ +import type { SVGProps } from 'react'; + +// Exported from the Figma Icons/Buttons frames (156:1559, 528:7117). Paths and +// root sizes are the exported ones; only the stroke is changed to +// `currentColor` so the parent button or filter can recolor them. They are +// decorative: put an aria-label on the wrapping button instead. +// +// Not in `icons/index.tsx` on purpose: #76 creates that file with its own +// UploadIcon, and sharing a path would conflict on merge. Consolidate later. + +type IconProps = Omit, 'children'>; + +const common = { + fill: 'none', + 'aria-hidden': true, + focusable: false, +} as const; + +const stroke = { + stroke: 'currentColor', + strokeLinecap: 'round', + strokeLinejoin: 'round', +} as const; + +export const UploadIcon: React.FC = (props) => ( + + + +); + +export const RefreshIcon: React.FC = (props) => ( + + + +); + +export const AddTextIcon: React.FC = (props) => ( + + + +); + +/** Small right-pointing chevron from the Source button, rotated 90deg in + * Figma so it points down. The wrapper has the rotated 15.8 x 14 box. */ +export const ChevronDownIcon: React.FC = (props) => ( + +); + +/** Large green right chevron of the icon-only "Open" button. */ +export const ChevronRightIcon: React.FC = (props) => ( + + + +); + +export const CalendarIcon: React.FC = (props) => ( + + + + +); + +/** Filter dropdown chevron: same idea as ChevronDownIcon, 17.5 x 19.8, drawn + * rotated 90deg in Figma, wrapper holds the rotated 19.8 x 17.5 box. */ +export const FilterChevronIcon: React.FC = (props) => ( + +); diff --git a/apps/frontend/src/components/index.ts b/apps/frontend/src/components/index.ts new file mode 100644 index 000000000..f61a3cfef --- /dev/null +++ b/apps/frontend/src/components/index.ts @@ -0,0 +1,2 @@ +export * from './Button'; +export * from './Filter'; diff --git a/apps/frontend/src/containers/buttons-filters-preview.tsx b/apps/frontend/src/containers/buttons-filters-preview.tsx new file mode 100644 index 000000000..8cc506a5d --- /dev/null +++ b/apps/frontend/src/containers/buttons-filters-preview.tsx @@ -0,0 +1,265 @@ +import { useState } from 'react'; +import { + Button, + type ButtonVariant, + type ButtonSize, +} from '@components/Button'; +import { Filter } from '@components/Filter'; +import { + AddTextIcon, + CalendarIcon, + ChevronDownIcon, + ChevronRightIcon, + RefreshIcon, + UploadIcon, +} from '@components/icons/ButtonIcons'; +import { + DATE_PRESETS, + DEFAULT_DATE, + DEFAULT_UPLOADER, + MOCK_ENTRIES, + UPLOADER_OPTIONS, + filterEntries, +} from './mockFilters'; + +// Temporary dev-only page (#94) for checking Button and Filter against Figma +// frames 156:1559, 528:7117 and 528:7052. + +const row = { + display: 'flex', + flexWrap: 'wrap', + alignItems: 'center', + gap: 'var(--space-4)', +} as const; + +const section = { + background: 'var(--color-bg-card)', + border: '1px solid var(--color-border)', + borderRadius: 'var(--radius-md)', + padding: 'var(--space-6)', + display: 'grid', + gap: 'var(--space-4)', +} as const; + +const caption = { + font: 'var(--text-caption)', + color: 'var(--color-text-muted)', +} as const; + +const dateOptions = DATE_PRESETS.map(({ value, label }) => ({ value, label })); + +// One entry per Figma button: label, variant, icons. +const FIGMA_BUTTONS: { + label: string; + variant: ButtonVariant; + left?: React.ReactNode; + right?: React.ReactNode; +}[] = [ + { label: 'Upload', variant: 'primary', left: }, + { label: 'Re-Upload', variant: 'primary', left: }, + { label: 'Refresh', variant: 'primary', left: }, + { label: 'Source: All', variant: 'primary', right: }, + { label: 'Download', variant: 'primary' }, + { label: 'Cancel', variant: 'secondary' }, + { label: 'Close', variant: 'secondary' }, + { label: 'Submit', variant: 'primary' }, + { label: 'Add Text', variant: 'primary', left: }, + { label: 'Clear Filters', variant: 'dark' }, + { label: 'Today’s Entry', variant: 'link' }, +]; + +const SIZES: ButtonSize[] = ['md', 'sm']; + +const ButtonsSection: React.FC = () => ( +
+

Buttons

+ {SIZES.map((size) => ( +
+ size {size}: default +
+ {FIGMA_BUTTONS.map((b) => ( + + ))} +
+ size {size}: disabled +
+ {FIGMA_BUTTONS.map((b) => ( + + ))} +
+ size {size}: loading +
+ {FIGMA_BUTTONS.filter((b) => b.variant !== 'link').map((b) => ( + + ))} + +
+
+ ))} + link variant as a real anchor +
+ +
+
+); + +const FiltersSection: React.FC = () => { + const [date, setDate] = useState(DEFAULT_DATE); + const [uploader, setUploader] = useState(DEFAULT_UPLOADER); + return ( +
+

Filters

+
+
+ } + width="442px" + /> + selected: {date} +
+
+ + selected: {uploader} +
+
+ + disabled +
+
+ + size sm +
+
+
+ ); +}; + +// Composed like Figma 528:7052 / 531:16311. +const FilterBarSection: React.FC = () => { + const [date, setDate] = useState(DEFAULT_DATE); + const [uploader, setUploader] = useState(DEFAULT_UPLOADER); + const count = filterEntries(MOCK_ENTRIES, date, uploader).length; + const reset = () => { + setDate(DEFAULT_DATE); + setUploader(DEFAULT_UPLOADER); + }; + return ( +
+

Filter bar

+
+ } + width="442px" + /> + + + {count} {count === 1 ? 'entry' : 'entries'} + +
+ {count === 0 ? ( +
+ + No entries match these filters. +
+ ) : null} + + Tip: pick “Sep 1 - Sep 30, 2026” to see 0 entries and Clear Filters. + +
+ ); +}; + +const ButtonsFiltersPreview: React.FC = () => ( +
+

Button and Filter

+ + + +
+); + +export default ButtonsFiltersPreview; diff --git a/apps/frontend/src/containers/mockFilters.ts b/apps/frontend/src/containers/mockFilters.ts new file mode 100644 index 000000000..2c4133b7d --- /dev/null +++ b/apps/frontend/src/containers/mockFilters.ts @@ -0,0 +1,69 @@ +import type { FilterOption } from '@components/Filter'; + +// Mock data for the /dev/buttons preview. Dates are fixed so the page is the +// same every day. + +export interface MockEntry { + id: number; + date: string; // ISO yyyy-mm-dd + uploader: 'intern' | 'admin'; +} + +export const MOCK_ENTRIES: MockEntry[] = [ + { id: 1, date: '2026-10-02', uploader: 'intern' }, + { id: 2, date: '2026-10-05', uploader: 'admin' }, + { id: 3, date: '2026-10-12', uploader: 'intern' }, + { id: 4, date: '2026-10-19', uploader: 'intern' }, + { id: 5, date: '2026-10-23', uploader: 'admin' }, + { id: 6, date: '2026-10-27', uploader: 'intern' }, + { id: 7, date: '2026-10-30', uploader: 'admin' }, + { id: 8, date: '2026-11-01', uploader: 'intern' }, +]; + +/** Preset date ranges. A real range picker can replace this later: keep the + * `{ value, label }` shape so `Filter` doesn't change. [from, to], inclusive. */ +export const DATE_PRESETS: (FilterOption & { range: [string, string] })[] = [ + { + value: 'oct-nov', + label: 'Oct 1 - Nov 1, 2026', + range: ['2026-10-01', '2026-11-01'], + }, + { + value: 'last-7', + label: 'Last 7 days', + range: ['2026-10-26', '2026-11-01'], + }, + { + value: 'last-30', + label: 'Last 30 days', + range: ['2026-10-03', '2026-11-01'], + }, + { + value: 'sep', + label: 'Sep 1 - Sep 30, 2026', + range: ['2026-09-01', '2026-09-30'], + }, +]; + +export const UPLOADER_OPTIONS: FilterOption[] = [ + { value: 'all', label: 'All uploaders' }, + { value: 'intern', label: 'Intern' }, + { value: 'admin', label: 'Admin' }, +]; + +export const DEFAULT_DATE = 'oct-nov'; +export const DEFAULT_UPLOADER = 'all'; + +export function filterEntries( + entries: MockEntry[], + dateValue: string, + uploader: string, +): MockEntry[] { + const preset = DATE_PRESETS.find((p) => p.value === dateValue); + return entries.filter((e) => { + const inRange = preset + ? e.date >= preset.range[0] && e.date <= preset.range[1] + : true; + return inRange && (uploader === 'all' || e.uploader === uploader); + }); +} From 9409bb8e6aab926f94dd446babfe6780992b02c5 Mon Sep 17 00:00:00 2001 From: Angie Che Date: Sun, 22 Nov 2026 16:27:44 -0500 Subject: [PATCH 2/4] Document Button, Filter and icons; rename mock uploader intern to staff --- .../frontend/src/components/Button/Button.tsx | 24 +++++++++++++++---- .../src/components/Button/variants.ts | 3 +++ .../src/components/Filter/Filter.spec.tsx | 12 +++++----- .../frontend/src/components/Filter/Filter.tsx | 24 ++++++++++++++++--- .../src/components/icons/ButtonIcons.tsx | 4 ++++ .../containers/buttons-filters-preview.tsx | 8 ++++++- apps/frontend/src/containers/mockFilters.ts | 14 +++++------ 7 files changed, 68 insertions(+), 21 deletions(-) diff --git a/apps/frontend/src/components/Button/Button.tsx b/apps/frontend/src/components/Button/Button.tsx index 94d400227..666eb9bb9 100644 --- a/apps/frontend/src/components/Button/Button.tsx +++ b/apps/frontend/src/components/Button/Button.tsx @@ -43,10 +43,26 @@ const Icon = ({ children }: { children: ReactNode }) => ( ); /** - * Chakra's Button dressed with the Figma "Buttons" frame (156:1559), using the - * tokens from `styles/tokens.css`. Chakra props such as `onClick`, `disabled`, - * `asChild` and `aria-*` pass through. `type` defaults to "button" so a button - * in a form never submits by accident. + * Shared button. Built on Chakra's `Button` and styled with the tokens in + * `styles/tokens.css` to match the Figma "Buttons" frame (156:1559). + * + * - `variant` is the look (`primary`, `secondary`, `dark`, `link`, `ghost`). + * The caller passes the label and icons, so there is no variant per label. + * - `size` is `md` (Figma's 40px) or `sm` (compact, not in Figma). + * - `loading` shows a spinner, disables the button and sets `aria-busy`; + * `loadingText` replaces the label while loading. + * - `href` renders a real ``. `asChild` wraps your own element (e.g. a + * router Link) and leaves its content and `type` alone. + * - `type` defaults to `"button"` so a button in a form never submits by + * accident. Pass `type="submit"` for Submit. + * - With no children it is icon-only and `aria-label` is required. + * + * Other Chakra props (`onClick`, `disabled`, `aria-*`, ...) pass through. + * + * @example + * + * + * + * * - * - + ); /** Both Filter types (date and uploader) with mock options, the selected * value printed below each, plus the disabled and `sm` states. */ -const FiltersSection: React.FC = () => { +export const FiltersDemo: React.FC = () => { const [date, setDate] = useState(DEFAULT_DATE); const [uploader, setUploader] = useState(DEFAULT_UPLOADER); return ( -
-

Filters

-
-
- } - width="442px" - /> - selected: {date} -
-
- - selected: {uploader} -
-
- - disabled -
-
- - size sm -
+
+
+ } + width="442px" + /> + selected: {date} +
+
+ + selected: {uploader} +
+
+ + disabled
-
+
+ + size sm +
+ ); }; /** Filters composed like Figma 528:7052 / 531:16311: labels, an entry count * driven by the mock data, and Clear Filters when nothing matches. */ -const FilterBarSection: React.FC = () => { +export const FilterBarDemo: React.FC = () => { const [date, setDate] = useState(DEFAULT_DATE); const [uploader, setUploader] = useState(DEFAULT_UPLOADER); const count = filterEntries(MOCK_ENTRIES, date, uploader).length; @@ -212,15 +219,14 @@ const FilterBarSection: React.FC = () => { setUploader(DEFAULT_UPLOADER); }; return ( -
-

Filter bar

+ <>
} + icon={} width="442px" /> { Tip: pick “Sep 1 - Sep 30, 2026” to see 0 entries and Clear Filters. -
+ ); }; - -/** Dev-only page at `/dev/buttons`, not in production navigation. */ -const ButtonsFiltersPreview: React.FC = () => ( -
-

Button and Filter

- - - -
-); - -export default ButtonsFiltersPreview; diff --git a/apps/frontend/src/containers/design.tsx b/apps/frontend/src/containers/design.tsx index 166b27e33..92cedaf62 100644 --- a/apps/frontend/src/containers/design.tsx +++ b/apps/frontend/src/containers/design.tsx @@ -9,6 +9,7 @@ import { type ErrorLogSource, } from '@components/ErrorLogTable'; import { SubmittedEntriesTable } from '@components/SubmittedEntriesTable'; +import { ButtonsDemo, FiltersDemo, FilterBarDemo } from './button-filter-demo'; const SHADES = [100, 200, 300, 400, 500, 600, 700, 800]; const PALETTE: [string, number[]][] = [ @@ -231,6 +232,21 @@ const Design: React.FC = () => (

Tables

+ +
+

Buttons

+ +
+ +
+

Filters

+ +
+ +
+

Filter bar

+ +
); From 155c3afb67ebf6d5e4373731b558c1854ea62d4d Mon Sep 17 00:00:00 2001 From: Angie Che Date: Sun, 22 Nov 2026 17:43:00 -0500 Subject: [PATCH 4/4] minor comment changes --- apps/frontend/src/components/Button/variants.ts | 8 +++----- apps/frontend/src/components/Filter/Filter.tsx | 8 +++----- apps/frontend/src/containers/button-filter-demo.tsx | 2 +- 3 files changed, 7 insertions(+), 11 deletions(-) diff --git a/apps/frontend/src/components/Button/variants.ts b/apps/frontend/src/components/Button/variants.ts index 60a6efe7b..cc1beba1a 100644 --- a/apps/frontend/src/components/Button/variants.ts +++ b/apps/frontend/src/components/Button/variants.ts @@ -55,14 +55,12 @@ export const BUTTON_VARIANTS: Record = { borderColor: 'var(--color-primary)', color: 'var(--color-text-inverse)', _hover: { bg: PRIMARY_HOVER, borderColor: PRIMARY_HOVER }, - // Pressed state is an assumption (--sea-green-600 is in the variables - // but not in the frames). _active: { bg: 'var(--sea-green-600)', borderColor: 'var(--sea-green-600)', }, }, - // Cancel, Close. Figma's border is 1.5px. + // Cancel, Close. secondary: { ...base, bg: 'var(--color-bg-card)', @@ -87,7 +85,7 @@ export const BUTTON_VARIANTS: Record = { borderColor: 'var(--deep-blue-500)', }, }, - // Today's Entry: Arial bold 14/24 underlined text, green when "Clicked". + // Today's Entry: green when "Clicked" link: { ...base, h: 'auto', @@ -103,7 +101,7 @@ export const BUTTON_VARIANTS: Record = { _hover: { color: 'var(--sea-green-600)', bg: 'transparent' }, _active: { color: 'var(--sea-green-600)', bg: 'transparent' }, }, - // Open: green chevron only, no background. + // Open: green chevron with no background ghost: { ...base, h: '32px', diff --git a/apps/frontend/src/components/Filter/Filter.tsx b/apps/frontend/src/components/Filter/Filter.tsx index 7df971abb..c82d7c082 100644 --- a/apps/frontend/src/components/Filter/Filter.tsx +++ b/apps/frontend/src/components/Filter/Filter.tsx @@ -11,17 +11,15 @@ export interface FilterProps { /** Visible label above the trigger ("Date range", "Uploaded by"). */ label?: string; options: FilterOption[]; - /** Controlled value. */ value: string; onChange: (value: string) => void; - /** Shown when `value` matches no option. */ + // Shown when `value` matches no option. placeholder?: string; - /** Leading icon, e.g. the calendar on the date filter. Decorative. */ + // Icon in trigger's top right corner icon?: React.ReactNode; - /** `md` is Figma's 54px. `sm` is a compact option (not in Figma). */ size?: 'sm' | 'md'; disabled?: boolean; - /** Figma widths differ per filter (date ~442px, uploader ~346px). */ + // Widths differ per filter (date ~442px, uploader ~346px). width?: string | number; } diff --git a/apps/frontend/src/containers/button-filter-demo.tsx b/apps/frontend/src/containers/button-filter-demo.tsx index 20406caa7..1feec4127 100644 --- a/apps/frontend/src/containers/button-filter-demo.tsx +++ b/apps/frontend/src/containers/button-filter-demo.tsx @@ -208,7 +208,7 @@ export const FiltersDemo: React.FC = () => { ); }; -/** Filters composed like Figma 528:7052 / 531:16311: labels, an entry count +/** Filters composed into a bar: labels, an entry count * driven by the mock data, and Clear Filters when nothing matches. */ export const FilterBarDemo: React.FC = () => { const [date, setDate] = useState(DEFAULT_DATE);