@milktop/react-ui 0.3.4 → 0.3.5

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.
@@ -14,6 +14,9 @@
14
14
  * - `size`: 'sm', 'md' (default) or 'lg': the width (or height for top and bottom)
15
15
  * - `open`, `defaultOpen`, `onOpenChange`, `trigger`, `heading`, `description`,
16
16
  * `footer`, `closable`, `alert`: as for Dialog
17
+ * - `modal`: false keeps the page usable beside it (no backdrop, no focus
18
+ * trap, the page still scrolls, a click outside doesn't close it), for
19
+ * looking something up while working on the page
17
20
  *
18
21
  * Or composed from Sheet.Header (heading, description), Sheet.Body and
19
22
  * Sheet.Footer, with a Sheet.Trigger child, as Dialog is. By hand, Dialog's
@@ -35,6 +38,7 @@ export type SheetProps = Omit<Ark.ContentProps, 'children'> & {
35
38
  heading?: ReactNode;
36
39
  description?: ReactNode;
37
40
  alert?: boolean;
41
+ modal?: boolean;
38
42
  closable?: boolean;
39
43
  trigger?: ReactElement | null;
40
44
  footer?: ReactNode;
@@ -46,7 +50,7 @@ type HeaderProps = ComponentProps<'div'> & {
46
50
  description?: ReactNode;
47
51
  };
48
52
  declare function Header({ heading, description, children, ...rest }: HeaderProps): import("react").JSX.Element;
49
- declare function SheetShortcut({ open, defaultOpen, onOpenChange, side, size, heading, description, alert, closable, trigger, footer, className, classes, children, ...rest }: SheetProps): import("react").JSX.Element;
53
+ declare function SheetShortcut({ open, defaultOpen, onOpenChange, side, size, heading, description, alert, modal, closable, trigger, footer, className, classes, children, ...rest }: SheetProps): import("react").JSX.Element;
50
54
  export declare const Sheet: typeof SheetShortcut & {
51
55
  Header: typeof Header;
52
56
  Body: {
@@ -15,6 +15,9 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
15
15
  * - `size`: 'sm', 'md' (default) or 'lg': the width (or height for top and bottom)
16
16
  * - `open`, `defaultOpen`, `onOpenChange`, `trigger`, `heading`, `description`,
17
17
  * `footer`, `closable`, `alert`: as for Dialog
18
+ * - `modal`: false keeps the page usable beside it (no backdrop, no focus
19
+ * trap, the page still scrolls, a click outside doesn't close it), for
20
+ * looking something up while working on the page
18
21
  *
19
22
  * Or composed from Sheet.Header (heading, description), Sheet.Body and
20
23
  * Sheet.Footer, with a Sheet.Trigger child, as Dialog is. By hand, Dialog's
@@ -43,14 +46,14 @@ const withScope = (Part, name) => {
43
46
  Scoped.displayName = `Sheet.${name}`;
44
47
  return Scoped;
45
48
  };
46
- function SheetShortcut({ open, defaultOpen, onOpenChange, side = 'right', size = 'md', heading = null, description = null, alert = false, closable = true, trigger = null, footer = null, className, classes, children, ...rest }) {
49
+ function SheetShortcut({ open, defaultOpen, onOpenChange, side = 'right', size = 'md', heading = null, description = null, alert = false, modal = true, closable = true, trigger = null, footer = null, className, classes, children, ...rest }) {
47
50
  const t = useMessages();
48
51
  const part = partsOf('sheet', classes);
49
52
  const nodes = Children.toArray(children);
50
53
  const composed = nodes.some((node) => isValidElement(node) && layout.includes(node.type));
51
54
  const triggers = nodes.filter((node) => isValidElement(node) && node.type === Ark.Trigger);
52
55
  const content = composed ? nodes.filter((node) => !triggers.includes(node)) : children;
53
- return (_jsxs(Ark.Root, { ...(open !== undefined && { open }), ...(defaultOpen !== undefined && { defaultOpen }), ...on('onOpenChange', onOpenChange, (details) => details.open), role: alert ? 'alertdialog' : 'dialog', closeOnInteractOutside: !alert, lazyMount: true, unmountOnExit: true, children: [trigger && _jsx(Ark.Trigger, { asChild: true, children: trigger }), composed && triggers, _jsxs(Portal, { children: [_jsx(Ark.Backdrop, { ...part('backdrop') }), _jsx(Ark.Positioner, { ...part('positioner'), "data-side": side, children: _jsxs(Ark.Content, { ...rest, ...part('content'), className: cx(className, classes?.content), "data-side": side, "data-size": size, children: [closable && _jsx(Ark.CloseTrigger, { ...part('close-trigger'), "aria-label": t.common.close, children: _jsx("iconify-icon", { icon: "lucide:x" }) }), composed ? content : _jsxs(_Fragment, { children: [(heading || description) && (_jsxs("div", { ...part('header'), children: [heading && _jsx(Ark.Title, { ...part('title'), children: heading }), description && _jsx(Ark.Description, { ...part('description'), children: description })] })), _jsx("div", { ...part('body'), children: children }), footer && _jsx("div", { ...part('footer'), children: footer })] })] }) })] })] }));
56
+ return (_jsxs(Ark.Root, { ...(open !== undefined && { open }), ...(defaultOpen !== undefined && { defaultOpen }), ...on('onOpenChange', onOpenChange, (details) => details.open), role: alert ? 'alertdialog' : 'dialog', modal: modal, trapFocus: modal, preventScroll: modal, closeOnInteractOutside: modal && !alert, lazyMount: true, unmountOnExit: true, children: [trigger && _jsx(Ark.Trigger, { asChild: true, children: trigger }), composed && triggers, _jsxs(Portal, { children: [modal && _jsx(Ark.Backdrop, { ...part('backdrop') }), _jsx(Ark.Positioner, { ...part('positioner'), "data-side": side, children: _jsxs(Ark.Content, { ...rest, ...part('content'), className: cx(className, classes?.content), "data-side": side, "data-size": size, children: [closable && _jsx(Ark.CloseTrigger, { ...part('close-trigger'), "aria-label": t.common.close, children: _jsx("iconify-icon", { icon: "lucide:x" }) }), composed ? content : _jsxs(_Fragment, { children: [(heading || description) && (_jsxs("div", { ...part('header'), children: [heading && _jsx(Ark.Title, { ...part('title'), children: heading }), description && _jsx(Ark.Description, { ...part('description'), children: description })] })), _jsx("div", { ...part('body'), children: children }), footer && _jsx("div", { ...part('footer'), children: footer })] })] }) })] })] }));
54
57
  }
55
58
  export const Sheet = withParts(SheetShortcut, {
56
59
  Header, Body, Footer,
@@ -14,6 +14,8 @@
14
14
  * - `variant`: 'line' (default, an underline) or 'pills'
15
15
  * - `counts`: where the tabs' counts sit: 'inline' (default, after the label)
16
16
  * or 'corner' (top right, like a button's)
17
+ * - `iconOnly`: tabs with an icon show just the icon, their label in a
18
+ * tooltip (and still read out); tabs without one keep their label
17
19
  * - `renderTrigger`: a tab's content, given the tab's props; its count still follows
18
20
  *
19
21
  * By hand, with Ark's parts (data-variant on the root picks the look):
@@ -68,10 +70,11 @@ export type TabsProps = Omit<Ark.RootProps, 'value' | 'defaultValue' | 'onValueC
68
70
  onValueChange?: (value: Value | null, details: TabsValueChangeDetails) => void;
69
71
  variant?: 'line' | 'pills';
70
72
  counts?: 'inline' | 'corner';
73
+ iconOnly?: boolean;
71
74
  renderTrigger?: (tab: TabProps) => ReactNode;
72
- classes?: Classes<'root' | 'list' | 'trigger' | 'icon' | 'count' | 'indicator' | 'panels' | 'content'>;
75
+ classes?: Classes<'root' | 'list' | 'trigger' | 'tipTarget' | 'icon' | 'count' | 'indicator' | 'panels' | 'content'>;
73
76
  };
74
- declare function TabsShortcut({ value, defaultValue, onValueChange, variant, counts, renderTrigger, className, classes, children, ...rest }: TabsProps): import("react").JSX.Element;
77
+ declare function TabsShortcut({ value, defaultValue, onValueChange, variant, counts, iconOnly, renderTrigger, className, classes, children, ...rest }: TabsProps): import("react").JSX.Element;
75
78
  export declare const Tabs: typeof TabsShortcut & {
76
79
  Tab: typeof Tab;
77
80
  Root: import("react").ForwardRefExoticComponent<Ark.RootProps & import("react").RefAttributes<HTMLDivElement>>;
package/dist/tabs/Tabs.js CHANGED
@@ -15,6 +15,8 @@ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-run
15
15
  * - `variant`: 'line' (default, an underline) or 'pills'
16
16
  * - `counts`: where the tabs' counts sit: 'inline' (default, after the label)
17
17
  * or 'corner' (top right, like a button's)
18
+ * - `iconOnly`: tabs with an icon show just the icon, their label in a
19
+ * tooltip (and still read out); tabs without one keep their label
18
20
  * - `renderTrigger`: a tab's content, given the tab's props; its count still follows
19
21
  *
20
22
  * By hand, with Ark's parts (data-variant on the root picks the look):
@@ -32,6 +34,7 @@ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-run
32
34
  import { Children, isValidElement, useEffect } from 'react';
33
35
  import { Tabs as Ark } from '@ark-ui/react/tabs';
34
36
  import '../icons.js';
37
+ import { Tooltip } from '../tooltip/Tooltip.js';
35
38
  import { cx, partOf, partsOf, useControllable, withParts } from '../utils.js';
36
39
  import '../theme.css';
37
40
  import './tabs.css';
@@ -52,7 +55,7 @@ import './tabs.css';
52
55
  export function Tab({ value, label: _label, icon: _icon, disabled: _disabled, count: _count, max: _max, dot: _dot, pulse: _pulse, countColor: _countColor, countLabel: _countLabel, className, ...rest }) {
53
56
  return _jsx(Ark.Content, { ...rest, value: String(value), "data-scope": "tabs", "data-part": "content", className: className });
54
57
  }
55
- function TabsShortcut({ value, defaultValue, onValueChange, variant = 'line', counts = 'inline', renderTrigger, className, classes, children, ...rest }) {
58
+ function TabsShortcut({ value, defaultValue, onValueChange, variant = 'line', counts = 'inline', iconOnly = false, renderTrigger, className, classes, children, ...rest }) {
56
59
  const part = partsOf('tabs', classes);
57
60
  const tabs = Children.toArray(children).filter((child) => isValidElement(child) && child.type === Tab);
58
61
  // With no value, the first enabled tab.
@@ -76,7 +79,8 @@ function TabsShortcut({ value, defaultValue, onValueChange, variant = 'line', co
76
79
  const { count, max = 99, dot, pulse, countColor = 'neutral', countLabel = '' } = tab;
77
80
  const badge = count && count > 0 ? (count > max ? `${max}+` : String(count)) : dot ? '' : null;
78
81
  const spoken = count && count > 0 ? [count, countLabel].filter(Boolean).join(' ') : dot ? countLabel : '';
79
- return (_jsxs(Ark.Trigger, { value: String(tab.value), disabled: !!tab.disabled, ...part('trigger'), children: [renderTrigger ? renderTrigger(tab) : _jsxs(_Fragment, { children: [tab.icon && _jsx("iconify-icon", { ...part('icon'), icon: tab.icon, "aria-hidden": "true" }), _jsx("span", { children: tab.label })] }), badge != null && _jsxs(_Fragment, { children: [_jsx("span", { ...part('count'), "aria-hidden": "true", "data-dot": badge === '' || undefined, "data-pulse": pulse || undefined, "data-color": countColor, children: badge }), spoken && _jsxs("span", { ...part('sr-only'), children: [", ", spoken] })] })] }, String(tab.value)));
82
+ const bare = iconOnly && !!tab.icon;
83
+ return (_jsxs(Ark.Trigger, { value: String(tab.value), disabled: !!tab.disabled, ...part('trigger'), "data-icon-only": bare || undefined, children: [renderTrigger ? renderTrigger(tab) : bare ? _jsxs(_Fragment, { children: [_jsx(Tooltip, { content: tab.label, placement: "bottom", children: _jsx("span", { ...part('tip-target'), children: _jsx("iconify-icon", { ...part('icon'), icon: tab.icon, "aria-hidden": "true" }) }) }), _jsx("span", { ...part('sr-only'), children: tab.label })] }) : _jsxs(_Fragment, { children: [tab.icon && _jsx("iconify-icon", { ...part('icon'), icon: tab.icon, "aria-hidden": "true" }), _jsx("span", { children: tab.label })] }), badge != null && _jsxs(_Fragment, { children: [_jsx("span", { ...part('count'), "aria-hidden": "true", "data-dot": badge === '' || undefined, "data-pulse": pulse || undefined, "data-color": countColor, children: badge }), spoken && _jsxs("span", { ...part('sr-only'), children: [", ", spoken] })] })] }, String(tab.value)));
80
84
  }), _jsx(Ark.Indicator, { ...part('indicator') })] }), _jsx("div", { ...part('panels'), children: children })] }));
81
85
  }
82
86
  export const Tabs = withParts(TabsShortcut, {
@@ -40,6 +40,11 @@
40
40
  /* A tab with a corner count makes room for it on the right. */
41
41
  [data-counts=corner] [data-scope=tabs][data-part=trigger]:has(> [data-part=count]) { padding-right: 1.375rem;
42
42
  &:has(> [data-dot]) { padding-right: 1.125rem; } }
43
+ /* Icon only: the tooltip's target fills the tab, so its whole width shows the label on hover. */
44
+ [data-scope=tabs][data-part=trigger][data-icon-only] { padding: 0;
45
+ [data-counts=corner] &:has(> [data-part=count]) { padding-right: 0; }
46
+ [data-counts=inline] & > [data-part=count] { margin: 0 0.75rem 0 -0.375rem; } }
47
+ [data-scope=tabs][data-part=tip-target] { display: grid; place-items: center; align-self: stretch; padding: 0 0.75rem; }
43
48
  [data-scope=tabs][data-part=sr-only] { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
44
49
  @keyframes ui-ping { from { scale: 1; opacity: 0.7; } 75%, to { scale: 2.2; opacity: 0; } }
45
50
  @media (prefers-reduced-motion: reduce) { [data-scope=tabs][data-part=count]::after { animation: none; } }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@milktop/react-ui",
3
- "version": "0.3.4",
3
+ "version": "0.3.5",
4
4
  "description": "React components on Ark UI (Zag state machines), with imba-ui's API and design",
5
5
  "license": "MIT",
6
6
  "author": "André Goldstein",