@kennycorrea/ui 1.7.0 → 1.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.8.0 — 2026-10-27
4
+
5
+ An `Accordion` organism.
6
+
7
+ - **`Accordion`, `AccordionItem`, `AccordionTrigger`, `AccordionContent`.** Built on native `<details>`/`<summary>`, so keyboard and screen-reader support come from the browser. `type="multiple"` (default) or `"single"`; controlled with `value`/`onValueChange` or uncontrolled with `defaultValue`. The trigger takes any content and wraps; a chevron turns when open and stays still under reduced motion. Content mounts only while its item is open, unless `keepMounted` is set on the Accordion or the item. No built-in strings. Example in `examples/Accordions.tsx`; axe-checked in light and dark in `test/Accordion.test.tsx`.
8
+
3
9
  ## 1.7.0 — 2026-10-23
4
10
 
5
11
  Sidebar groups as an accordion, and select-all for stacked tables.
@@ -0,0 +1,34 @@
1
+ import { type ComponentPropsWithoutRef, type ReactNode } from 'react';
2
+ export interface AccordionProps {
3
+ /** `multiple` lets any number be open; `single` closes the others when one opens. */
4
+ type?: 'multiple' | 'single';
5
+ /** The open items. Controlled when given, with `onValueChange`. */
6
+ value?: string[];
7
+ defaultValue?: string[];
8
+ onValueChange?: (value: string[]) => void;
9
+ /** Keep every item's content mounted while closed. Each item can override it. */
10
+ keepMounted?: boolean;
11
+ className?: string;
12
+ children: ReactNode;
13
+ }
14
+ /**
15
+ * A stack of collapsible sections, each a native `<details>`/`<summary>`: the summary is the
16
+ * button, so keyboard (Enter/Space), focus and the expanded state reach assistive technology
17
+ * without any ARIA of our own. Open state lives in React, so `value` can be controlled.
18
+ * Content mounts only while open unless `keepMounted` is set.
19
+ */
20
+ export declare function Accordion({ type, value, defaultValue, onValueChange, keepMounted, className, children, }: AccordionProps): import("react").JSX.Element;
21
+ export interface AccordionItemProps extends Omit<ComponentPropsWithoutRef<'details'>, 'open' | 'onToggle'> {
22
+ value: string;
23
+ /** Overrides the Accordion's `keepMounted` for this item. */
24
+ keepMounted?: boolean;
25
+ }
26
+ export declare function AccordionItem({ value, keepMounted, className, children, ...rest }: AccordionItemProps): import("react").JSX.Element;
27
+ export interface AccordionTriggerProps extends ComponentPropsWithoutRef<'summary'> {
28
+ /** Hide the chevron, e.g. when the trigger draws its own. */
29
+ hideChevron?: boolean;
30
+ }
31
+ /** The row that opens and closes the item. Takes any content: a logo, a name, badges, meta. */
32
+ export declare function AccordionTrigger({ className, children, onClick, hideChevron, ...rest }: AccordionTriggerProps): import("react").JSX.Element;
33
+ export type AccordionContentProps = ComponentPropsWithoutRef<'div'>;
34
+ export declare function AccordionContent({ className, ...rest }: AccordionContentProps): import("react").JSX.Element | null;
@@ -0,0 +1,63 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { ChevronDownIcon } from '@radix-ui/react-icons';
3
+ import { createContext, useCallback, useContext, useState, } from 'react';
4
+ import { cn } from '../../utils/index.js';
5
+ const AccordionContext = createContext(null);
6
+ const ItemContext = createContext(null);
7
+ function useAccordion() {
8
+ const ctx = useContext(AccordionContext);
9
+ if (!ctx)
10
+ throw new Error('AccordionItem must be used inside an Accordion');
11
+ return ctx;
12
+ }
13
+ function useItem() {
14
+ const ctx = useContext(ItemContext);
15
+ if (!ctx)
16
+ throw new Error('AccordionTrigger and AccordionContent must be inside an AccordionItem');
17
+ return ctx;
18
+ }
19
+ /**
20
+ * A stack of collapsible sections, each a native `<details>`/`<summary>`: the summary is the
21
+ * button, so keyboard (Enter/Space), focus and the expanded state reach assistive technology
22
+ * without any ARIA of our own. Open state lives in React, so `value` can be controlled.
23
+ * Content mounts only while open unless `keepMounted` is set.
24
+ */
25
+ export function Accordion({ type = 'multiple', value, defaultValue, onValueChange, keepMounted = false, className, children, }) {
26
+ const [inner, setInner] = useState(defaultValue ?? []);
27
+ const open = value ?? inner;
28
+ const toggle = useCallback((item) => {
29
+ const next = open.includes(item)
30
+ ? open.filter((v) => v !== item)
31
+ : type === 'single'
32
+ ? [item]
33
+ : [...open, item];
34
+ if (value === undefined)
35
+ setInner(next);
36
+ onValueChange?.(next);
37
+ }, [open, type, value, onValueChange]);
38
+ const isOpen = useCallback((item) => open.includes(item), [open]);
39
+ return (_jsx(AccordionContext.Provider, { value: { isOpen, toggle, keepMounted }, children: _jsx("div", { className: cn('ui-accordion', className), children: children }) }));
40
+ }
41
+ export function AccordionItem({ value, keepMounted, className, children, ...rest }) {
42
+ const acc = useAccordion();
43
+ const open = acc.isOpen(value);
44
+ return (_jsx(ItemContext.Provider, { value: { value, open, keepMounted: keepMounted ?? acc.keepMounted }, children: _jsx("details", { ...rest, open: open, className: cn('ui-accordion__item', className), children: children }) }));
45
+ }
46
+ /** The row that opens and closes the item. Takes any content: a logo, a name, badges, meta. */
47
+ export function AccordionTrigger({ className, children, onClick, hideChevron = false, ...rest }) {
48
+ const acc = useAccordion();
49
+ const item = useItem();
50
+ const handleClick = (e) => {
51
+ onClick?.(e);
52
+ // The browser would flip `open` itself; React owns it instead so `value` stays the truth.
53
+ e.preventDefault();
54
+ acc.toggle(item.value);
55
+ };
56
+ return (_jsxs("summary", { ...rest, onClick: handleClick, className: cn('ui-accordion__trigger', className), children: [children, hideChevron ? null : (_jsx("span", { "aria-hidden": "true", className: "ui-accordion__chevron", children: _jsx(ChevronDownIcon, {}) }))] }));
57
+ }
58
+ export function AccordionContent({ className, ...rest }) {
59
+ const item = useItem();
60
+ if (!item.open && !item.keepMounted)
61
+ return null;
62
+ return _jsx("div", { ...rest, className: cn('ui-accordion__content', className) });
63
+ }
@@ -0,0 +1 @@
1
+ export * from './Accordion.js';
@@ -0,0 +1 @@
1
+ export * from './Accordion.js';
@@ -1,3 +1,4 @@
1
+ export * from './Accordion/index.js';
1
2
  export * from './AppShell/index.js';
2
3
  export * from './AuthForms/index.js';
3
4
  export * from './BulkActionBar/index.js';
@@ -1,3 +1,4 @@
1
+ export * from './Accordion/index.js';
1
2
  export * from './AppShell/index.js';
2
3
  export * from './AuthForms/index.js';
3
4
  export * from './BulkActionBar/index.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kennycorrea/ui",
3
- "version": "1.7.0",
3
+ "version": "1.8.0",
4
4
  "description": "A React + TypeScript component library built on Radix Themes: atoms, a Tailwind token bridge and theming.",
5
5
  "private": false,
6
6
  "type": "module",
package/tokens.css CHANGED
@@ -1415,3 +1415,26 @@
1415
1415
  .rt-TextAreaRoot:has(> textarea[aria-invalid="true"]),
1416
1416
  .rt-SelectTrigger[aria-invalid="true"],
1417
1417
  .ui-date-input.rt-Button[aria-invalid="true"] { box-shadow: inset 0 0 0 1px var(--red-8); }
1418
+
1419
+ /* Accordion: native <details>, its marker replaced by a chevron that turns when open. */
1420
+ .ui-accordion { display: flex; flex-direction: column; gap: 8px; }
1421
+ .ui-accordion__item {
1422
+ border-radius: var(--radius-3, 8px);
1423
+ border: 1px solid var(--color-hairline);
1424
+ background: var(--color-panel-solid);
1425
+ color: var(--color-ink, inherit);
1426
+ }
1427
+ .ui-accordion__trigger {
1428
+ display: flex; flex-wrap: wrap; align-items: center; column-gap: 12px; row-gap: 4px;
1429
+ padding: 16px; cursor: pointer; list-style: none; border-radius: inherit;
1430
+ }
1431
+ .ui-accordion__trigger::-webkit-details-marker { display: none; }
1432
+ .ui-accordion__trigger::marker { content: ""; }
1433
+ .ui-accordion__trigger:focus-visible { outline: 2px solid var(--focus-8, var(--accent-8)); outline-offset: 2px; }
1434
+ .ui-accordion__chevron { display: inline-flex; margin-inline-start: auto; transition: transform 150ms ease; }
1435
+ .ui-accordion__item[open] > .ui-accordion__trigger .ui-accordion__chevron { transform: rotate(180deg); }
1436
+ .ui-accordion__content { border-top: 1px solid var(--color-hairline); padding: 16px; }
1437
+ @media (prefers-reduced-motion: reduce) {
1438
+ .ui-accordion__chevron { transition: none; }
1439
+ .ui-accordion__item[open] > .ui-accordion__trigger .ui-accordion__chevron { transform: none; }
1440
+ }