@mohirlab/react 0.3.0 → 0.5.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/dist/components/choice/choice.d.ts +46 -0
- package/dist/components/choice/choice.d.ts.map +1 -0
- package/dist/components/choice/choice.js +184 -0
- package/dist/components/choice/choice.js.map +1 -0
- package/dist/components/choice/choice.styles.js +21 -0
- package/dist/components/choice/choice.styles.js.map +1 -0
- package/dist/components/choice/index.d.ts +2 -0
- package/dist/components/field/use-field-control.js +21 -0
- package/dist/components/field/use-field-control.js.map +1 -0
- package/dist/components/input/index.d.ts +2 -2
- package/dist/components/input/input.css.d.ts.map +1 -1
- package/dist/components/input/input.d.ts +12 -0
- package/dist/components/input/input.d.ts.map +1 -1
- package/dist/components/input/input.js +32 -11
- package/dist/components/input/input.js.map +1 -1
- package/dist/components/input/input.styles.js +3 -1
- package/dist/components/navigation/index.d.ts +3 -0
- package/dist/components/navigation/nav.d.ts +67 -0
- package/dist/components/navigation/nav.d.ts.map +1 -0
- package/dist/components/navigation/nav.js +144 -0
- package/dist/components/navigation/nav.js.map +1 -0
- package/dist/components/navigation/navigation.styles.js +21 -0
- package/dist/components/navigation/navigation.styles.js.map +1 -0
- package/dist/components/navigation/tabs.d.ts +30 -0
- package/dist/components/navigation/tabs.d.ts.map +1 -0
- package/dist/components/navigation/tabs.js +97 -0
- package/dist/components/navigation/tabs.js.map +1 -0
- package/dist/components/select/index.d.ts +2 -0
- package/dist/components/select/select.d.ts +14 -0
- package/dist/components/select/select.d.ts.map +1 -0
- package/dist/components/select/select.js +44 -0
- package/dist/components/select/select.js.map +1 -0
- package/dist/components/select/select.styles.js +7 -0
- package/dist/components/select/select.styles.js.map +1 -0
- package/dist/components/slider/index.d.ts +2 -0
- package/dist/components/slider/slider.d.ts +18 -0
- package/dist/components/slider/slider.d.ts.map +1 -0
- package/dist/components/slider/slider.js +50 -0
- package/dist/components/slider/slider.js.map +1 -0
- package/dist/components/slider/slider.styles.js +7 -0
- package/dist/components/slider/slider.styles.js.map +1 -0
- package/dist/index.d.ts +11 -2
- package/dist/index.js +8 -3
- package/dist/styles.css +706 -47
- package/package.json +6 -5
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { useId, useState } from "react";
|
|
2
|
+
import { iconArrowLeft, iconChevronRight } from "@mohirlab/icons";
|
|
3
|
+
import { cx } from "../../utils/cx.js";
|
|
4
|
+
import { Icon } from "../icon/icon.js";
|
|
5
|
+
import { bottomBadge, bottomItem, bottomNav, bottomNavSpacer, crumb, crumbCurrent, crumbLink, crumbs, segment, segmentInput, segmentLabel, segmented } from "./navigation.styles.js";
|
|
6
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
7
|
+
// src/components/navigation/nav.tsx
|
|
8
|
+
/**
|
|
9
|
+
* One choice from two to five short options, such as a view or a time range. Native
|
|
10
|
+
* radios underneath: arrow keys move the choice, and it submits with forms.
|
|
11
|
+
*/
|
|
12
|
+
function SegmentedControl({ options, value, defaultValue, onValueChange, name, fullWidth, className, ...rest }) {
|
|
13
|
+
const generated = useId();
|
|
14
|
+
const [internal, setInternal] = useState(defaultValue ?? options[0]?.value);
|
|
15
|
+
const current = value ?? internal;
|
|
16
|
+
return /* @__PURE__ */ jsx("div", {
|
|
17
|
+
...rest,
|
|
18
|
+
role: "radiogroup",
|
|
19
|
+
"data-full-width": fullWidth || void 0,
|
|
20
|
+
className: cx(segmented, className),
|
|
21
|
+
children: options.map((option) => /* @__PURE__ */ jsxs("label", {
|
|
22
|
+
className: segment,
|
|
23
|
+
children: [/* @__PURE__ */ jsx("input", {
|
|
24
|
+
type: "radio",
|
|
25
|
+
className: segmentInput,
|
|
26
|
+
name: name ?? `ml-seg-${generated}`,
|
|
27
|
+
value: option.value,
|
|
28
|
+
checked: current === option.value,
|
|
29
|
+
disabled: option.disabled,
|
|
30
|
+
onChange: () => {
|
|
31
|
+
if (value === void 0) setInternal(option.value);
|
|
32
|
+
onValueChange?.(option.value);
|
|
33
|
+
}
|
|
34
|
+
}), /* @__PURE__ */ jsxs("span", {
|
|
35
|
+
className: segmentLabel,
|
|
36
|
+
children: [option.icon && /* @__PURE__ */ jsx(Icon, {
|
|
37
|
+
icon: option.icon,
|
|
38
|
+
size: 16
|
|
39
|
+
}), option.label]
|
|
40
|
+
})]
|
|
41
|
+
}, option.value))
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* The phone tab bar: three to five top-level destinations, fixed to the bottom and
|
|
46
|
+
* clear of the home indicator. Add a `BottomNavSpacer` at the end of the page so
|
|
47
|
+
* content can scroll past it.
|
|
48
|
+
*/
|
|
49
|
+
function BottomNav({ hideFrom = "tablet", className, ...rest }) {
|
|
50
|
+
return /* @__PURE__ */ jsx("nav", {
|
|
51
|
+
...rest,
|
|
52
|
+
"data-hide-from": hideFrom,
|
|
53
|
+
className: cx(bottomNav, className)
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
function BottomNavItem({ icon, label, current, badge, className, ...rest }) {
|
|
57
|
+
const content = /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
58
|
+
/* @__PURE__ */ jsx(Icon, {
|
|
59
|
+
icon,
|
|
60
|
+
size: 22
|
|
61
|
+
}),
|
|
62
|
+
/* @__PURE__ */ jsx("span", { children: label }),
|
|
63
|
+
badge ? /* @__PURE__ */ jsx("span", {
|
|
64
|
+
className: bottomBadge,
|
|
65
|
+
"aria-hidden": "true",
|
|
66
|
+
children: badge > 99 ? "99+" : badge
|
|
67
|
+
}) : null
|
|
68
|
+
] });
|
|
69
|
+
const shared = {
|
|
70
|
+
className: cx(bottomItem, className),
|
|
71
|
+
"aria-current": current ? "page" : void 0,
|
|
72
|
+
"aria-label": badge ? `${label}, ${badge}` : void 0
|
|
73
|
+
};
|
|
74
|
+
if (rest.href !== void 0) return /* @__PURE__ */ jsx("a", {
|
|
75
|
+
...rest,
|
|
76
|
+
...shared,
|
|
77
|
+
children: content
|
|
78
|
+
});
|
|
79
|
+
return /* @__PURE__ */ jsx("button", {
|
|
80
|
+
type: "button",
|
|
81
|
+
...rest,
|
|
82
|
+
...shared,
|
|
83
|
+
children: content
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
/** Reserves room under the page content for the bottom nav (on the same breakpoints). */
|
|
87
|
+
function BottomNavSpacer({ hideFrom = "tablet" }) {
|
|
88
|
+
return /* @__PURE__ */ jsx("div", {
|
|
89
|
+
"aria-hidden": "true",
|
|
90
|
+
"data-hide-from": hideFrom,
|
|
91
|
+
className: bottomNavSpacer
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Where the current page sits in the hierarchy. On phones it collapses to a single
|
|
96
|
+
* "← Parent" back link, the thing people actually use a trail for on a small screen.
|
|
97
|
+
*/
|
|
98
|
+
function Breadcrumbs({ items, className, "aria-label": ariaLabel = "Breadcrumb", ...rest }) {
|
|
99
|
+
const parent = items.length > 1 ? items[items.length - 2] : void 0;
|
|
100
|
+
return /* @__PURE__ */ jsx("nav", {
|
|
101
|
+
...rest,
|
|
102
|
+
"aria-label": ariaLabel,
|
|
103
|
+
className,
|
|
104
|
+
children: /* @__PURE__ */ jsxs("ol", {
|
|
105
|
+
className: crumbs,
|
|
106
|
+
children: [parent?.href && /* @__PURE__ */ jsx("li", {
|
|
107
|
+
className: "ml_gp95tng",
|
|
108
|
+
children: /* @__PURE__ */ jsxs("a", {
|
|
109
|
+
className: "ml_gp95tnd",
|
|
110
|
+
href: parent.href,
|
|
111
|
+
children: [
|
|
112
|
+
/* @__PURE__ */ jsx(Icon, {
|
|
113
|
+
icon: iconArrowLeft,
|
|
114
|
+
size: 16
|
|
115
|
+
}),
|
|
116
|
+
" ",
|
|
117
|
+
parent.label
|
|
118
|
+
]
|
|
119
|
+
})
|
|
120
|
+
}), items.map((item, index) => {
|
|
121
|
+
const last = index === items.length - 1;
|
|
122
|
+
return /* @__PURE__ */ jsxs("li", {
|
|
123
|
+
className: crumb,
|
|
124
|
+
children: [last || !item.href ? /* @__PURE__ */ jsx("span", {
|
|
125
|
+
className: crumbCurrent,
|
|
126
|
+
"aria-current": last ? "page" : void 0,
|
|
127
|
+
children: item.label
|
|
128
|
+
}) : /* @__PURE__ */ jsx("a", {
|
|
129
|
+
className: crumbLink,
|
|
130
|
+
href: item.href,
|
|
131
|
+
children: item.label
|
|
132
|
+
}), !last && /* @__PURE__ */ jsx(Icon, {
|
|
133
|
+
icon: iconChevronRight,
|
|
134
|
+
size: 14,
|
|
135
|
+
className: "ml_gp95tnf"
|
|
136
|
+
})]
|
|
137
|
+
}, index);
|
|
138
|
+
})]
|
|
139
|
+
})
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
export { BottomNav, BottomNavItem, BottomNavSpacer, Breadcrumbs, SegmentedControl };
|
|
143
|
+
|
|
144
|
+
//# sourceMappingURL=nav.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nav.js","names":["styles.segmented","styles.segment","styles.segmentInput","styles.segmentLabel","styles.bottomNav","styles.bottomBadge","styles.bottomItem","styles.bottomNavSpacer","styles.crumbs","styles.crumb","styles.crumbCurrent","styles.crumbLink"],"sources":["../../../src/components/navigation/nav.tsx"],"sourcesContent":["import { useId, useState, type ComponentPropsWithRef, type ReactNode } from 'react';\nimport { iconArrowLeft, iconChevronRight, type IconData } from '@mohirlab/icons';\nimport { cx } from '../../utils/cx';\nimport { Icon } from '../icon';\nimport * as styles from './navigation.css';\n\n/* ---------------------------------------------------- Segmented control */\n\nexport interface SegmentedOption {\n value: string;\n label: ReactNode;\n icon?: IconData;\n disabled?: boolean;\n}\n\nexport interface SegmentedControlProps extends Omit<\n ComponentPropsWithRef<'div'>,\n 'defaultValue' | 'onChange' | 'children'\n> {\n /** Names the choice, e.g. \"View\". */\n 'aria-label': string;\n options: SegmentedOption[];\n value?: string;\n defaultValue?: string;\n onValueChange?: (value: string) => void;\n name?: string;\n /** Stretch to the container width, segments sharing it equally. */\n fullWidth?: boolean;\n}\n\n/**\n * One choice from two to five short options, such as a view or a time range. Native\n * radios underneath: arrow keys move the choice, and it submits with forms.\n */\nexport function SegmentedControl({\n options,\n value,\n defaultValue,\n onValueChange,\n name,\n fullWidth,\n className,\n ...rest\n}: SegmentedControlProps) {\n const generated = useId();\n const [internal, setInternal] = useState(defaultValue ?? options[0]?.value);\n const current = value ?? internal;\n return (\n <div\n {...rest}\n role=\"radiogroup\"\n data-full-width={fullWidth || undefined}\n className={cx(styles.segmented, className)}\n >\n {options.map((option) => (\n <label key={option.value} className={styles.segment}>\n <input\n type=\"radio\"\n className={styles.segmentInput}\n name={name ?? `ml-seg-${generated}`}\n value={option.value}\n checked={current === option.value}\n disabled={option.disabled}\n onChange={() => {\n if (value === undefined) setInternal(option.value);\n onValueChange?.(option.value);\n }}\n />\n <span className={styles.segmentLabel}>\n {option.icon && <Icon icon={option.icon} size={16} />}\n {option.label}\n </span>\n </label>\n ))}\n </div>\n );\n}\n\n/* ---------------------------------------------------------- Bottom nav */\n\nexport interface BottomNavProps extends ComponentPropsWithRef<'nav'> {\n /** Names the navigation, e.g. \"Main\". */\n 'aria-label': string;\n /** Hide from this breakpoint up, where a sidebar or top bar takes over. Default tablet. */\n hideFrom?: 'tablet' | 'desktop' | 'never';\n}\n\n/**\n * The phone tab bar: three to five top-level destinations, fixed to the bottom and\n * clear of the home indicator. Add a `BottomNavSpacer` at the end of the page so\n * content can scroll past it.\n */\nexport function BottomNav({ hideFrom = 'tablet', className, ...rest }: BottomNavProps) {\n return <nav {...rest} data-hide-from={hideFrom} className={cx(styles.bottomNav, className)} />;\n}\n\ntype BottomNavItemProps = {\n icon: IconData;\n label: string;\n /** Marks the current destination (`aria-current=\"page\"`). */\n current?: boolean;\n /** A count such as unread messages; announced with the label. */\n badge?: number;\n className?: string;\n} & (\n | ({ href: string } & Omit<ComponentPropsWithRef<'a'>, 'children'>)\n | ({ href?: undefined } & Omit<ComponentPropsWithRef<'button'>, 'children'>)\n);\n\nexport function BottomNavItem({ icon, label, current, badge, className, ...rest }: BottomNavItemProps) {\n const content = (\n <>\n <Icon icon={icon} size={22} />\n <span>{label}</span>\n {badge ? (\n <span className={styles.bottomBadge} aria-hidden=\"true\">\n {badge > 99 ? '99+' : badge}\n </span>\n ) : null}\n </>\n );\n const shared = {\n className: cx(styles.bottomItem, className),\n 'aria-current': current ? ('page' as const) : undefined,\n // The visual badge is hidden; the count is part of the accessible name instead.\n 'aria-label': badge ? `${label}, ${badge}` : undefined,\n };\n if (rest.href !== undefined) {\n return (\n <a {...(rest as ComponentPropsWithRef<'a'>)} {...shared}>\n {content}\n </a>\n );\n }\n return (\n <button type=\"button\" {...(rest as ComponentPropsWithRef<'button'>)} {...shared}>\n {content}\n </button>\n );\n}\n\n/** Reserves room under the page content for the bottom nav (on the same breakpoints). */\nexport function BottomNavSpacer({ hideFrom = 'tablet' }: Pick<BottomNavProps, 'hideFrom'>) {\n return <div aria-hidden=\"true\" data-hide-from={hideFrom} className={styles.bottomNavSpacer} />;\n}\n\n/* --------------------------------------------------------- Breadcrumbs */\n\nexport interface Crumb {\n label: ReactNode;\n href?: string;\n}\n\nexport interface BreadcrumbsProps extends Omit<ComponentPropsWithRef<'nav'>, 'children'> {\n /** From the top level down to the current page (last, not linked). */\n items: Crumb[];\n}\n\n/**\n * Where the current page sits in the hierarchy. On phones it collapses to a single\n * \"← Parent\" back link, the thing people actually use a trail for on a small screen.\n */\nexport function Breadcrumbs({\n items,\n className,\n 'aria-label': ariaLabel = 'Breadcrumb',\n ...rest\n}: BreadcrumbsProps) {\n const parent = items.length > 1 ? items[items.length - 2] : undefined;\n return (\n <nav {...rest} aria-label={ariaLabel} className={className}>\n <ol className={styles.crumbs}>\n {parent?.href && (\n <li className={styles.crumbBack}>\n <a className={styles.crumbLink} href={parent.href}>\n <Icon icon={iconArrowLeft} size={16} /> {parent.label}\n </a>\n </li>\n )}\n {items.map((item, index) => {\n const last = index === items.length - 1;\n return (\n <li key={index} className={styles.crumb}>\n {last || !item.href ? (\n <span className={styles.crumbCurrent} aria-current={last ? 'page' : undefined}>\n {item.label}\n </span>\n ) : (\n <a className={styles.crumbLink} href={item.href}>\n {item.label}\n </a>\n )}\n {!last && <Icon icon={iconChevronRight} size={14} className={styles.crumbSeparator} />}\n </li>\n );\n })}\n </ol>\n </nav>\n );\n}\n"],"mappings":"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"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// src/components/navigation/navigation.css.ts
|
|
2
|
+
var bottomBadge = "ml_gp95tn9";
|
|
3
|
+
var bottomItem = "ml_gp95tn8";
|
|
4
|
+
var bottomNav = "ml_gp95tn7";
|
|
5
|
+
var bottomNavSpacer = "ml_gp95tna";
|
|
6
|
+
var crumb = "ml_gp95tnc";
|
|
7
|
+
var crumbBack = "ml_gp95tng";
|
|
8
|
+
var crumbCurrent = "ml_gp95tne";
|
|
9
|
+
var crumbLink = "ml_gp95tnd";
|
|
10
|
+
var crumbSeparator = "ml_gp95tnf";
|
|
11
|
+
var crumbs = "ml_gp95tnb";
|
|
12
|
+
var segment = "ml_gp95tn4";
|
|
13
|
+
var segmentInput = "ml_gp95tn5";
|
|
14
|
+
var segmentLabel = "ml_gp95tn6";
|
|
15
|
+
var segmented = "ml_gp95tn3";
|
|
16
|
+
var tab = "ml_gp95tn1";
|
|
17
|
+
var tabList = "ml_gp95tn0";
|
|
18
|
+
var tabPanel = "ml_gp95tn2";
|
|
19
|
+
export { bottomBadge, bottomItem, bottomNav, bottomNavSpacer, crumb, crumbBack, crumbCurrent, crumbLink, crumbSeparator, crumbs, segment, segmentInput, segmentLabel, segmented, tab, tabList, tabPanel };
|
|
20
|
+
|
|
21
|
+
//# sourceMappingURL=navigation.styles.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"navigation.styles.js","names":[],"sources":[],"mappings":""}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { ComponentPropsWithRef, ReactNode } from "react";
|
|
2
|
+
export interface TabsProps extends Omit<ComponentPropsWithRef<'div'>, 'defaultValue' | 'onChange'> {
|
|
3
|
+
/** The selected tab (controlled). */
|
|
4
|
+
value?: string;
|
|
5
|
+
/** The tab selected first (uncontrolled). One of `value` or `defaultValue` is required. */
|
|
6
|
+
defaultValue?: string;
|
|
7
|
+
onValueChange?: (value: string) => void;
|
|
8
|
+
children: ReactNode;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Tabs switch between panels of related content in place. For moving between pages,
|
|
12
|
+
* use links instead. Follows the WAI-ARIA tabs pattern with automatic activation.
|
|
13
|
+
*/
|
|
14
|
+
export declare function Tabs({ value, defaultValue, onValueChange, children, ...rest }: TabsProps): import("react").JSX.Element;
|
|
15
|
+
export interface TabListProps extends ComponentPropsWithRef<'div'> {
|
|
16
|
+
/** Names the set of tabs, e.g. "Invoice views". */
|
|
17
|
+
'aria-label': string;
|
|
18
|
+
}
|
|
19
|
+
/** The row of tabs. Arrow keys, Home and End move between tabs and select them. */
|
|
20
|
+
export declare function TabList({ className, onKeyDown, ...rest }: TabListProps): import("react").JSX.Element;
|
|
21
|
+
export interface TabProps extends Omit<ComponentPropsWithRef<'button'>, 'value'> {
|
|
22
|
+
value: string;
|
|
23
|
+
}
|
|
24
|
+
export declare function Tab({ value, className, onClick, ...rest }: TabProps): import("react").JSX.Element;
|
|
25
|
+
export interface TabPanelProps extends ComponentPropsWithRef<'div'> {
|
|
26
|
+
value: string;
|
|
27
|
+
}
|
|
28
|
+
/** Content for one tab. Hidden panels stay in the DOM (state is kept) but are not shown. */
|
|
29
|
+
export declare function TabPanel({ value, className, ...rest }: TabPanelProps): import("react").JSX.Element;
|
|
30
|
+
//# sourceMappingURL=tabs.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tabs.d.ts","names":[],"sources":["../../../src/components/navigation/tabs.tsx"],"mappings":";iBAyBiB,kBAAkB,KAAK;;EAEtC;;EAEA;EACA,iBAAiB;EACjB,UAAU;;;;;;wBAOI,OAAO,OAAO,cAAmB,eAAe,aAAa,QAAQ,4BAAS,IAAA;iBAmB7E,qBAAqB;;EAEpC;;;wBAIc,UAAU,WAAW,cAAc,QAAQ,+BAAY,IAAA;iBAyBtD,iBAAiB,KAAK;EACrC;;wBAGc,MAAM,OAAO,WAAW,YAAY,QAAQ,2BAAQ,IAAA;iBAsBnD,sBAAsB;EACrC;;;wBAIc,WAAW,OAAO,cAAc,QAAQ,gCAAa,IAAA"}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { createContext, useContext, useId, useState } from "react";
|
|
2
|
+
import { cx } from "../../utils/cx.js";
|
|
3
|
+
import { tab, tabList, tabPanel } from "./navigation.styles.js";
|
|
4
|
+
import { jsx } from "react/jsx-runtime";
|
|
5
|
+
// src/components/navigation/tabs.tsx
|
|
6
|
+
const TabsContext = createContext(null);
|
|
7
|
+
const useTabs = () => {
|
|
8
|
+
const context = useContext(TabsContext);
|
|
9
|
+
if (!context) throw new Error("Tab parts must be used inside <Tabs>.");
|
|
10
|
+
return context;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Tabs switch between panels of related content in place. For moving between pages,
|
|
14
|
+
* use links instead. Follows the WAI-ARIA tabs pattern with automatic activation.
|
|
15
|
+
*/
|
|
16
|
+
function Tabs({ value, defaultValue = "", onValueChange, children, ...rest }) {
|
|
17
|
+
const base = useId();
|
|
18
|
+
const [internal, setInternal] = useState(defaultValue);
|
|
19
|
+
const context = {
|
|
20
|
+
value: value ?? internal,
|
|
21
|
+
select: (next) => {
|
|
22
|
+
if (value === void 0) setInternal(next);
|
|
23
|
+
onValueChange?.(next);
|
|
24
|
+
},
|
|
25
|
+
idFor: (kind, v) => `${base}-${kind}-${v.replace(/[^\w-]/g, "_")}`
|
|
26
|
+
};
|
|
27
|
+
return /* @__PURE__ */ jsx(TabsContext.Provider, {
|
|
28
|
+
value: context,
|
|
29
|
+
children: /* @__PURE__ */ jsx("div", {
|
|
30
|
+
...rest,
|
|
31
|
+
children
|
|
32
|
+
})
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
/** The row of tabs. Arrow keys, Home and End move between tabs and select them. */
|
|
36
|
+
function TabList({ className, onKeyDown, ...rest }) {
|
|
37
|
+
const onKey = (event) => {
|
|
38
|
+
onKeyDown?.(event);
|
|
39
|
+
const tabs = [...event.currentTarget.querySelectorAll("[role=\"tab\"]:not(:disabled)")];
|
|
40
|
+
const index = tabs.indexOf(document.activeElement);
|
|
41
|
+
if (index === -1) return;
|
|
42
|
+
const rtl = getComputedStyle(event.currentTarget).direction === "rtl";
|
|
43
|
+
const step = {
|
|
44
|
+
ArrowRight: rtl ? -1 : 1,
|
|
45
|
+
ArrowLeft: rtl ? 1 : -1
|
|
46
|
+
}[event.key];
|
|
47
|
+
let next;
|
|
48
|
+
if (step) next = tabs[(index + step + tabs.length) % tabs.length];
|
|
49
|
+
else if (event.key === "Home") next = tabs[0];
|
|
50
|
+
else if (event.key === "End") next = tabs.at(-1);
|
|
51
|
+
if (!next) return;
|
|
52
|
+
event.preventDefault();
|
|
53
|
+
next.focus();
|
|
54
|
+
next.click();
|
|
55
|
+
};
|
|
56
|
+
return /* @__PURE__ */ jsx("div", {
|
|
57
|
+
...rest,
|
|
58
|
+
role: "tablist",
|
|
59
|
+
className: cx(tabList, className),
|
|
60
|
+
onKeyDown: onKey
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
function Tab({ value, className, onClick, ...rest }) {
|
|
64
|
+
const tabs = useTabs();
|
|
65
|
+
const selected = tabs.value === value;
|
|
66
|
+
return /* @__PURE__ */ jsx("button", {
|
|
67
|
+
...rest,
|
|
68
|
+
type: "button",
|
|
69
|
+
role: "tab",
|
|
70
|
+
id: tabs.idFor("tab", value),
|
|
71
|
+
"aria-controls": tabs.idFor("panel", value),
|
|
72
|
+
"aria-selected": selected,
|
|
73
|
+
tabIndex: selected ? 0 : -1,
|
|
74
|
+
className: cx(tab, className),
|
|
75
|
+
onClick: (event) => {
|
|
76
|
+
onClick?.(event);
|
|
77
|
+
tabs.select(value);
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
/** Content for one tab. Hidden panels stay in the DOM (state is kept) but are not shown. */
|
|
82
|
+
function TabPanel({ value, className, ...rest }) {
|
|
83
|
+
const tabs = useTabs();
|
|
84
|
+
const selected = tabs.value === value;
|
|
85
|
+
return /* @__PURE__ */ jsx("div", {
|
|
86
|
+
...rest,
|
|
87
|
+
role: "tabpanel",
|
|
88
|
+
id: tabs.idFor("panel", value),
|
|
89
|
+
"aria-labelledby": tabs.idFor("tab", value),
|
|
90
|
+
tabIndex: 0,
|
|
91
|
+
hidden: !selected,
|
|
92
|
+
className: cx(tabPanel, className)
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
export { Tab, TabList, TabPanel, Tabs };
|
|
96
|
+
|
|
97
|
+
//# sourceMappingURL=tabs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tabs.js","names":["styles.tabList","styles.tab","styles.tabPanel"],"sources":["../../../src/components/navigation/tabs.tsx"],"sourcesContent":["import {\n createContext,\n useContext,\n useId,\n useState,\n type ComponentPropsWithRef,\n type KeyboardEvent,\n type ReactNode,\n} from 'react';\nimport { cx } from '../../utils/cx';\nimport * as styles from './navigation.css';\n\ninterface TabsContextValue {\n value: string;\n select: (value: string) => void;\n idFor: (kind: 'tab' | 'panel', value: string) => string;\n}\n\nconst TabsContext = createContext<TabsContextValue | null>(null);\nconst useTabs = () => {\n const context = useContext(TabsContext);\n if (!context) throw new Error('Tab parts must be used inside <Tabs>.');\n return context;\n};\n\nexport interface TabsProps extends Omit<ComponentPropsWithRef<'div'>, 'defaultValue' | 'onChange'> {\n /** The selected tab (controlled). */\n value?: string;\n /** The tab selected first (uncontrolled). One of `value` or `defaultValue` is required. */\n defaultValue?: string;\n onValueChange?: (value: string) => void;\n children: ReactNode;\n}\n\n/**\n * Tabs switch between panels of related content in place. For moving between pages,\n * use links instead. Follows the WAI-ARIA tabs pattern with automatic activation.\n */\nexport function Tabs({ value, defaultValue = '', onValueChange, children, ...rest }: TabsProps) {\n const base = useId();\n const [internal, setInternal] = useState(defaultValue);\n const current = value ?? internal;\n const context: TabsContextValue = {\n value: current,\n select: (next) => {\n if (value === undefined) setInternal(next);\n onValueChange?.(next);\n },\n idFor: (kind, v) => `${base}-${kind}-${v.replace(/[^\\w-]/g, '_')}`,\n };\n return (\n <TabsContext.Provider value={context}>\n <div {...rest}>{children}</div>\n </TabsContext.Provider>\n );\n}\n\nexport interface TabListProps extends ComponentPropsWithRef<'div'> {\n /** Names the set of tabs, e.g. \"Invoice views\". */\n 'aria-label': string;\n}\n\n/** The row of tabs. Arrow keys, Home and End move between tabs and select them. */\nexport function TabList({ className, onKeyDown, ...rest }: TabListProps) {\n const onKey = (event: KeyboardEvent<HTMLDivElement>) => {\n onKeyDown?.(event);\n const tabs = [...event.currentTarget.querySelectorAll<HTMLButtonElement>('[role=\"tab\"]:not(:disabled)')];\n const index = tabs.indexOf(document.activeElement as HTMLButtonElement);\n if (index === -1) return;\n const rtl = getComputedStyle(event.currentTarget).direction === 'rtl';\n const step = { ArrowRight: rtl ? -1 : 1, ArrowLeft: rtl ? 1 : -1 }[event.key];\n let next: HTMLButtonElement | undefined;\n if (step) next = tabs[(index + step + tabs.length) % tabs.length];\n else if (event.key === 'Home') next = tabs[0];\n else if (event.key === 'End') next = tabs.at(-1);\n if (!next) return;\n event.preventDefault();\n next.focus();\n next.click();\n };\n return (\n // WAI-ARIA tabs pattern: focus lives on the tabs (roving tabindex), not on the list.\n // The list only handles keys that bubble up from the focused tab.\n // oxlint-disable-next-line jsx-a11y/interactive-supports-focus\n <div {...rest} role=\"tablist\" className={cx(styles.tabList, className)} onKeyDown={onKey} />\n );\n}\n\nexport interface TabProps extends Omit<ComponentPropsWithRef<'button'>, 'value'> {\n value: string;\n}\n\nexport function Tab({ value, className, onClick, ...rest }: TabProps) {\n const tabs = useTabs();\n const selected = tabs.value === value;\n return (\n <button\n {...rest}\n type=\"button\"\n role=\"tab\"\n id={tabs.idFor('tab', value)}\n aria-controls={tabs.idFor('panel', value)}\n aria-selected={selected}\n // Roving tabindex: Tab moves into the list once, arrows move within it.\n tabIndex={selected ? 0 : -1}\n className={cx(styles.tab, className)}\n onClick={(event) => {\n onClick?.(event);\n tabs.select(value);\n }}\n />\n );\n}\n\nexport interface TabPanelProps extends ComponentPropsWithRef<'div'> {\n value: string;\n}\n\n/** Content for one tab. Hidden panels stay in the DOM (state is kept) but are not shown. */\nexport function TabPanel({ value, className, ...rest }: TabPanelProps) {\n const tabs = useTabs();\n const selected = tabs.value === value;\n return (\n <div\n {...rest}\n role=\"tabpanel\"\n id={tabs.idFor('panel', value)}\n aria-labelledby={tabs.idFor('tab', value)}\n tabIndex={0}\n hidden={!selected}\n className={cx(styles.tabPanel, className)}\n />\n );\n}\n"],"mappings":";;;;;AAkBA,MAAM,cAAc,cAAuC,IAAI;AAC/D,MAAM,gBAAgB;CACpB,MAAM,UAAU,WAAW,WAAW;CACtC,IAAI,CAAC,SAAS,MAAM,IAAI,MAAM,uCAAuC;CACrE,OAAO;AACT;;;;;AAeA,SAAgB,KAAK,EAAE,OAAO,eAAe,IAAI,eAAe,UAAU,GAAG,QAAmB;CAC9F,MAAM,OAAO,MAAM;CACnB,MAAM,CAAC,UAAU,eAAe,SAAS,YAAY;CAErD,MAAM,UAA4B;EAChC,OAFc,SAAS;EAGvB,SAAS,SAAS;GAChB,IAAI,UAAU,KAAA,GAAW,YAAY,IAAI;GACzC,gBAAgB,IAAI;EACtB;EACA,QAAQ,MAAM,MAAM,GAAG,KAAK,GAAG,KAAK,GAAG,EAAE,QAAQ,WAAW,GAAG;CACjE;CACA,OACE,oBAAC,YAAY,UAAb;EAAsB,OAAO;EAC3B,UAAA,oBAAC,OAAD;GAAK,GAAI;GAAO;EAAc,CAAA;CACV,CAAA;AAE1B;;AAQA,SAAgB,QAAQ,EAAE,WAAW,WAAW,GAAG,QAAsB;CACvE,MAAM,SAAS,UAAyC;EACtD,YAAY,KAAK;EACjB,MAAM,OAAO,CAAC,GAAG,MAAM,cAAc,iBAAoC,+BAA6B,CAAC;EACvG,MAAM,QAAQ,KAAK,QAAQ,SAAS,aAAkC;EACtE,IAAI,UAAU,IAAI;EAClB,MAAM,MAAM,iBAAiB,MAAM,aAAa,CAAC,CAAC,cAAc;EAChE,MAAM,OAAO;GAAE,YAAY,MAAM,KAAK;GAAG,WAAW,MAAM,IAAI;EAAG,EAAE,MAAM;EACzE,IAAI;EACJ,IAAI,MAAM,OAAO,MAAM,QAAQ,OAAO,KAAK,UAAU,KAAK;OACrD,IAAI,MAAM,QAAQ,QAAQ,OAAO,KAAK;OACtC,IAAI,MAAM,QAAQ,OAAO,OAAO,KAAK,GAAG,EAAE;EAC/C,IAAI,CAAC,MAAM;EACX,MAAM,eAAe;EACrB,KAAK,MAAM;EACX,KAAK,MAAM;CACb;CACA,OAIE,oBAAC,OAAD;EAAK,GAAI;EAAM,MAAK;EAAU,WAAW,GAAGA,SAAgB,SAAS;EAAG,WAAW;CAAQ,CAAA;AAE/F;AAMA,SAAgB,IAAI,EAAE,OAAO,WAAW,SAAS,GAAG,QAAkB;CACpE,MAAM,OAAO,QAAQ;CACrB,MAAM,WAAW,KAAK,UAAU;CAChC,OACE,oBAAC,UAAD;EACE,GAAI;EACJ,MAAK;EACL,MAAK;EACL,IAAI,KAAK,MAAM,OAAO,KAAK;EAC3B,iBAAe,KAAK,MAAM,SAAS,KAAK;EACxC,iBAAe;EAEf,UAAU,WAAW,IAAI;EACzB,WAAW,GAAGC,KAAY,SAAS;EACnC,UAAU,UAAU;GAClB,UAAU,KAAK;GACf,KAAK,OAAO,KAAK;EACnB;CACD,CAAA;AAEL;;AAOA,SAAgB,SAAS,EAAE,OAAO,WAAW,GAAG,QAAuB;CACrE,MAAM,OAAO,QAAQ;CACrB,MAAM,WAAW,KAAK,UAAU;CAChC,OACE,oBAAC,OAAD;EACE,GAAI;EACJ,MAAK;EACL,IAAI,KAAK,MAAM,SAAS,KAAK;EAC7B,mBAAiB,KAAK,MAAM,OAAO,KAAK;EACxC,UAAU;EACV,QAAQ,CAAC;EACT,WAAW,GAAGC,UAAiB,SAAS;CACzC,CAAA;AAEL"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { ComponentPropsWithRef } from "react";
|
|
2
|
+
import { InputVariants } from "../input/input.css.js";
|
|
3
|
+
export interface SelectProps extends Omit<ComponentPropsWithRef<'select'>, 'size'> {
|
|
4
|
+
size?: InputVariants['size'];
|
|
5
|
+
invalid?: boolean;
|
|
6
|
+
/** Shown first and not selectable again once a choice is made, e.g. "Choose a country". */
|
|
7
|
+
placeholder?: string;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* The native `<select>`, styled like `Input`. Phones get the system picker, keyboards
|
|
11
|
+
* and screen readers get native behaviour, and forms submit it as is.
|
|
12
|
+
*/
|
|
13
|
+
export declare function Select({ size, invalid, placeholder, className, id, required, disabled, children, defaultValue, value, ...rest }: SelectProps): import("react").JSX.Element;
|
|
14
|
+
//# sourceMappingURL=select.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"select.d.ts","names":[],"sources":["../../../src/components/select/select.tsx"],"mappings":";;iBAQiB,oBAAoB,KAAK;EACxC,OAAO;EACP;;EAEA;;;;;;wBAOc,SACd,MACA,SACA,aACA,WACA,IACA,UACA,UACA,UACA,cACA,UACG,QACF,8BAAW,IAAA"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { iconChevronDown } from "@mohirlab/icons";
|
|
2
|
+
import { cx } from "../../utils/cx.js";
|
|
3
|
+
import { useFieldControl } from "../field/use-field-control.js";
|
|
4
|
+
import { Icon } from "../icon/icon.js";
|
|
5
|
+
import { input } from "../input/input.styles.js";
|
|
6
|
+
import { chevron, select, wrap } from "./select.styles.js";
|
|
7
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
8
|
+
// src/components/select/select.tsx
|
|
9
|
+
/**
|
|
10
|
+
* The native `<select>`, styled like `Input`. Phones get the system picker, keyboards
|
|
11
|
+
* and screen readers get native behaviour, and forms submit it as is.
|
|
12
|
+
*/
|
|
13
|
+
function Select({ size, invalid, placeholder, className, id, required, disabled, children, defaultValue, value, ...rest }) {
|
|
14
|
+
const control = useFieldControl({
|
|
15
|
+
id,
|
|
16
|
+
required,
|
|
17
|
+
disabled,
|
|
18
|
+
invalid,
|
|
19
|
+
"aria-describedby": rest["aria-describedby"]
|
|
20
|
+
});
|
|
21
|
+
const initial = placeholder && value === void 0 && defaultValue === void 0 ? "" : defaultValue;
|
|
22
|
+
return /* @__PURE__ */ jsxs("span", {
|
|
23
|
+
className: wrap,
|
|
24
|
+
children: [/* @__PURE__ */ jsxs("select", {
|
|
25
|
+
...rest,
|
|
26
|
+
...control,
|
|
27
|
+
value,
|
|
28
|
+
defaultValue: initial,
|
|
29
|
+
className: cx(input({ size }), select, className),
|
|
30
|
+
children: [placeholder && /* @__PURE__ */ jsx("option", {
|
|
31
|
+
value: "",
|
|
32
|
+
disabled: true,
|
|
33
|
+
children: placeholder
|
|
34
|
+
}), children]
|
|
35
|
+
}), /* @__PURE__ */ jsx(Icon, {
|
|
36
|
+
icon: iconChevronDown,
|
|
37
|
+
className: chevron,
|
|
38
|
+
size: 18
|
|
39
|
+
})]
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
export { Select };
|
|
43
|
+
|
|
44
|
+
//# sourceMappingURL=select.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"select.js","names":["styles.wrap","styles.select","styles.chevron"],"sources":["../../../src/components/select/select.tsx"],"sourcesContent":["import type { ComponentPropsWithRef } from 'react';\nimport { iconChevronDown } from '@mohirlab/icons';\nimport { cx } from '../../utils/cx';\nimport { useFieldControl } from '../field/use-field-control';\nimport { Icon } from '../icon';\nimport { input, type InputVariants } from '../input/input.css';\nimport * as styles from './select.css';\n\nexport interface SelectProps extends Omit<ComponentPropsWithRef<'select'>, 'size'> {\n size?: InputVariants['size'];\n invalid?: boolean;\n /** Shown first and not selectable again once a choice is made, e.g. \"Choose a country\". */\n placeholder?: string;\n}\n\n/**\n * The native `<select>`, styled like `Input`. Phones get the system picker, keyboards\n * and screen readers get native behaviour, and forms submit it as is.\n */\nexport function Select({\n size,\n invalid,\n placeholder,\n className,\n id,\n required,\n disabled,\n children,\n defaultValue,\n value,\n ...rest\n}: SelectProps) {\n const control = useFieldControl({\n id,\n required,\n disabled,\n invalid,\n 'aria-describedby': rest['aria-describedby'],\n });\n // With a placeholder and no value given, start on the placeholder option.\n const initial = placeholder && value === undefined && defaultValue === undefined ? '' : defaultValue;\n return (\n <span className={styles.wrap}>\n <select\n {...rest}\n {...control}\n value={value}\n defaultValue={initial}\n className={cx(input({ size }), styles.select, className)}\n >\n {placeholder && (\n <option value=\"\" disabled>\n {placeholder}\n </option>\n )}\n {children}\n </select>\n <Icon icon={iconChevronDown} className={styles.chevron} size={18} />\n </span>\n );\n}\n"],"mappings":";;;;;;;;;;;;AAmBA,SAAgB,OAAO,EACrB,MACA,SACA,aACA,WACA,IACA,UACA,UACA,UACA,cACA,OACA,GAAG,QACW;CACd,MAAM,UAAU,gBAAgB;EAC9B;EACA;EACA;EACA;EACA,oBAAoB,KAAK;CAC3B,CAAC;CAED,MAAM,UAAU,eAAe,UAAU,KAAA,KAAa,iBAAiB,KAAA,IAAY,KAAK;CACxF,OACE,qBAAC,QAAD;EAAM,WAAWA;EAAjB,UAAA,CACE,qBAAC,UAAD;GACE,GAAI;GACJ,GAAI;GACG;GACP,cAAc;GACd,WAAW,GAAG,MAAM,EAAE,KAAK,CAAC,GAAGC,QAAe,SAAS;GALzD,UAAA,CAOG,eACC,oBAAC,UAAD;IAAQ,OAAM;IAAG,UAAA;IACd,UAAA;GACK,CAAA,GAET,QACK;EACR,CAAA,GAAA,oBAAC,MAAD;GAAM,MAAM;GAAiB,WAAWC;GAAgB,MAAM;EAAK,CAAA,CAC/D;;AAEV"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"select.styles.js","names":[],"sources":[],"mappings":""}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { ComponentPropsWithRef, ReactNode } from "react";
|
|
2
|
+
export interface SliderProps extends Omit<ComponentPropsWithRef<'input'>, 'type' | 'value' | 'defaultValue' | 'size'> {
|
|
3
|
+
value?: number;
|
|
4
|
+
defaultValue?: number;
|
|
5
|
+
onValueChange?: (value: number) => void;
|
|
6
|
+
min?: number;
|
|
7
|
+
max?: number;
|
|
8
|
+
step?: number;
|
|
9
|
+
/** Format the value for `aria-valuetext` and for `SliderValue`, e.g. `(v) => \`${v}%\``. */
|
|
10
|
+
format?: (value: number) => string;
|
|
11
|
+
}
|
|
12
|
+
/** A native range input with a filled track. Arrow keys, Page Up/Down, Home and End work natively. */
|
|
13
|
+
export declare function Slider({ value, defaultValue, onValueChange, min, max, step, format, className, style, id, required, disabled, onChange, ...rest }: SliderProps): import("react").JSX.Element;
|
|
14
|
+
/** Label row for a slider inside a `Field`: puts the current value at the end. */
|
|
15
|
+
export declare function SliderValue({ children }: {
|
|
16
|
+
children: ReactNode;
|
|
17
|
+
}): import("react").JSX.Element;
|
|
18
|
+
//# sourceMappingURL=slider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"slider.d.ts","names":[],"sources":["../../../src/components/slider/slider.tsx"],"mappings":";iBAMiB,oBAAoB,KACnC;EAGA;EACA;EACA,iBAAiB;EACjB;EACA;EACA;;EAEA,UAAU;;;wBAII,SACd,OACA,cACA,eACA,KACA,KACA,MACA,QACA,WACA,OACA,IACA,UACA,UACA,aACG,QACF,8BAAW,IAAA;;wBA4BE,cAAc;EAAc,UAAU;oBAAW,IAAA"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { useState } from "react";
|
|
2
|
+
import { assignInlineVars } from "@vanilla-extract/dynamic";
|
|
3
|
+
import { cx } from "../../utils/cx.js";
|
|
4
|
+
import { useFieldControl } from "../field/use-field-control.js";
|
|
5
|
+
import { fill, output, slider } from "./slider.styles.js";
|
|
6
|
+
import { jsx } from "react/jsx-runtime";
|
|
7
|
+
// src/components/slider/slider.tsx
|
|
8
|
+
/** A native range input with a filled track. Arrow keys, Page Up/Down, Home and End work natively. */
|
|
9
|
+
function Slider({ value, defaultValue, onValueChange, min = 0, max = 100, step = 1, format, className, style, id, required, disabled, onChange, ...rest }) {
|
|
10
|
+
const control = useFieldControl({
|
|
11
|
+
id,
|
|
12
|
+
required,
|
|
13
|
+
disabled,
|
|
14
|
+
"aria-describedby": rest["aria-describedby"]
|
|
15
|
+
});
|
|
16
|
+
const [internal, setInternal] = useState(defaultValue ?? (min + max) / 2);
|
|
17
|
+
const current = value ?? internal;
|
|
18
|
+
const percent = max === min ? 0 : (current - min) / (max - min) * 100;
|
|
19
|
+
return /* @__PURE__ */ jsx("input", {
|
|
20
|
+
...rest,
|
|
21
|
+
...control,
|
|
22
|
+
type: "range",
|
|
23
|
+
min,
|
|
24
|
+
max,
|
|
25
|
+
step,
|
|
26
|
+
value: current,
|
|
27
|
+
"aria-valuetext": format?.(current),
|
|
28
|
+
onChange: (event) => {
|
|
29
|
+
onChange?.(event);
|
|
30
|
+
const next = Number(event.target.value);
|
|
31
|
+
if (value === void 0) setInternal(next);
|
|
32
|
+
onValueChange?.(next);
|
|
33
|
+
},
|
|
34
|
+
className: cx(slider, className),
|
|
35
|
+
style: {
|
|
36
|
+
...style,
|
|
37
|
+
...assignInlineVars({ [fill]: `${percent}%` })
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
/** Label row for a slider inside a `Field`: puts the current value at the end. */
|
|
42
|
+
function SliderValue({ children }) {
|
|
43
|
+
return /* @__PURE__ */ jsx("output", {
|
|
44
|
+
className: output,
|
|
45
|
+
children
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
export { Slider, SliderValue };
|
|
49
|
+
|
|
50
|
+
//# sourceMappingURL=slider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"slider.js","names":["styles.slider","styles.fill","styles.output"],"sources":["../../../src/components/slider/slider.tsx"],"sourcesContent":["import { useState, type ComponentPropsWithRef, type ReactNode } from 'react';\nimport { assignInlineVars } from '@vanilla-extract/dynamic';\nimport { cx } from '../../utils/cx';\nimport { useFieldControl } from '../field/use-field-control';\nimport * as styles from './slider.css';\n\nexport interface SliderProps extends Omit<\n ComponentPropsWithRef<'input'>,\n 'type' | 'value' | 'defaultValue' | 'size'\n> {\n value?: number;\n defaultValue?: number;\n onValueChange?: (value: number) => void;\n min?: number;\n max?: number;\n step?: number;\n /** Format the value for `aria-valuetext` and for `SliderValue`, e.g. `(v) => \\`${v}%\\``. */\n format?: (value: number) => string;\n}\n\n/** A native range input with a filled track. Arrow keys, Page Up/Down, Home and End work natively. */\nexport function Slider({\n value,\n defaultValue,\n onValueChange,\n min = 0,\n max = 100,\n step = 1,\n format,\n className,\n style,\n id,\n required,\n disabled,\n onChange,\n ...rest\n}: SliderProps) {\n const control = useFieldControl({ id, required, disabled, 'aria-describedby': rest['aria-describedby'] });\n const [internal, setInternal] = useState(defaultValue ?? (min + max) / 2);\n const current = value ?? internal;\n const percent = max === min ? 0 : ((current - min) / (max - min)) * 100;\n return (\n <input\n {...rest}\n {...control}\n type=\"range\"\n min={min}\n max={max}\n step={step}\n value={current}\n aria-valuetext={format?.(current)}\n onChange={(event) => {\n onChange?.(event);\n const next = Number(event.target.value);\n if (value === undefined) setInternal(next);\n onValueChange?.(next);\n }}\n className={cx(styles.slider, className)}\n style={{ ...style, ...assignInlineVars({ [styles.fill]: `${percent}%` }) }}\n />\n );\n}\n\n/** Label row for a slider inside a `Field`: puts the current value at the end. */\nexport function SliderValue({ children }: { children: ReactNode }) {\n return <output className={styles.output}>{children}</output>;\n}\n"],"mappings":";;;;;;;;AAqBA,SAAgB,OAAO,EACrB,OACA,cACA,eACA,MAAM,GACN,MAAM,KACN,OAAO,GACP,QACA,WACA,OACA,IACA,UACA,UACA,UACA,GAAG,QACW;CACd,MAAM,UAAU,gBAAgB;EAAE;EAAI;EAAU;EAAU,oBAAoB,KAAK;CAAoB,CAAC;CACxG,MAAM,CAAC,UAAU,eAAe,SAAS,iBAAiB,MAAM,OAAO,CAAC;CACxE,MAAM,UAAU,SAAS;CACzB,MAAM,UAAU,QAAQ,MAAM,KAAM,UAAU,QAAQ,MAAM,OAAQ;CACpE,OACE,oBAAC,SAAD;EACE,GAAI;EACJ,GAAI;EACJ,MAAK;EACA;EACA;EACC;EACN,OAAO;EACP,kBAAgB,SAAS,OAAO;EAChC,WAAW,UAAU;GACnB,WAAW,KAAK;GAChB,MAAM,OAAO,OAAO,MAAM,OAAO,KAAK;GACtC,IAAI,UAAU,KAAA,GAAW,YAAY,IAAI;GACzC,gBAAgB,IAAI;EACtB;EACA,WAAW,GAAGA,QAAe,SAAS;EACtC,OAAO;GAAE,GAAG;GAAO,GAAG,iBAAiB,GAAGC,OAAc,GAAG,QAAQ,GAAG,CAAC;EAAE;CAC1E,CAAA;AAEL;;AAGA,SAAgB,YAAY,EAAE,YAAqC;CACjE,OAAO,oBAAC,UAAD;EAAQ,WAAWC;EAAgB;CAAiB,CAAA;AAC7D"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"slider.styles.js","names":[],"sources":[],"mappings":""}
|
package/dist/index.d.ts
CHANGED
|
@@ -10,6 +10,8 @@ import "./components/button/index.js";
|
|
|
10
10
|
import { Card, CardHeader, CardProps } from "./components/card/card.js";
|
|
11
11
|
import { CardMedia, CardMediaProps } from "./components/card/card-media.js";
|
|
12
12
|
import "./components/card/index.js";
|
|
13
|
+
import { Checkbox, CheckboxProps, Radio, RadioGroup, RadioGroupProps, RadioProps, Switch, SwitchProps } from "./components/choice/choice.js";
|
|
14
|
+
import "./components/choice/index.js";
|
|
13
15
|
import { Dialog, DialogActions, DialogBody, DialogProps } from "./components/dialog/dialog.js";
|
|
14
16
|
import "./components/dialog/index.js";
|
|
15
17
|
import { Field, FieldProps } from "./components/field/field.js";
|
|
@@ -17,11 +19,18 @@ import { FieldContextValue, useField } from "./components/field/field-context.js
|
|
|
17
19
|
import "./components/field/index.js";
|
|
18
20
|
import { Icon, IconProps } from "./components/icon/icon.js";
|
|
19
21
|
import "./components/icon/index.js";
|
|
20
|
-
import { Input, InputProps } from "./components/input/input.js";
|
|
22
|
+
import { Input, InputProps, Textarea, TextareaProps } from "./components/input/input.js";
|
|
21
23
|
import "./components/input/index.js";
|
|
24
|
+
import { Tab, TabList, TabListProps, TabPanel, TabPanelProps, TabProps, Tabs, TabsProps } from "./components/navigation/tabs.js";
|
|
25
|
+
import { BottomNav, BottomNavItem, BottomNavProps, BottomNavSpacer, Breadcrumbs, BreadcrumbsProps, Crumb, SegmentedControl, SegmentedControlProps, SegmentedOption } from "./components/navigation/nav.js";
|
|
26
|
+
import "./components/navigation/index.js";
|
|
22
27
|
import { Placement } from "./components/popover/popover.css.js";
|
|
23
28
|
import { Popover, PopoverProps, Tooltip, TooltipProps } from "./components/popover/popover.js";
|
|
24
29
|
import "./components/popover/index.js";
|
|
30
|
+
import { Select, SelectProps } from "./components/select/select.js";
|
|
31
|
+
import "./components/select/index.js";
|
|
32
|
+
import { Slider, SliderProps, SliderValue } from "./components/slider/slider.js";
|
|
33
|
+
import "./components/slider/index.js";
|
|
25
34
|
import { Heading, HeadingProps, MarginProps, Text, TextProps } from "./components/text/text.js";
|
|
26
35
|
import "./components/text/index.js";
|
|
27
36
|
import { ToastOptions, ToastProvider, ToastProviderProps, ToastTone, useToast } from "./components/toast/toast.js";
|
|
@@ -31,4 +40,4 @@ import { PresenceState, usePresence } from "./hooks/use-presence.js";
|
|
|
31
40
|
import { useDisclosure } from "./hooks/use-disclosure.js";
|
|
32
41
|
import "./hooks/index.js";
|
|
33
42
|
import { cx } from "./utils/cx.js";
|
|
34
|
-
export { Avatar, AvatarGroup, type AvatarGroupProps, type AvatarProps, Badge, type BadgeProps, Box, type BoxProps, Button, type ButtonProps, Card, CardHeader, CardMedia, type CardMediaProps, type CardProps, Dialog, DialogActions, DialogBody, type DialogProps, Field, type FieldContextValue, type FieldProps, Heading, type HeadingProps, Icon, type IconProps, Input, type InputProps, type MarginProps, type Placement, Popover, type PopoverProps, type PresenceState, Stack, type StackProps, Text, type TextProps, ThemeScope, type ThemeScopeProps, type ToastOptions, ToastProvider, type ToastProviderProps, type ToastTone, Tooltip, type TooltipProps, cx, splitSprinkles, useDisclosure, useField, usePresence, useToast };
|
|
43
|
+
export { Avatar, AvatarGroup, type AvatarGroupProps, type AvatarProps, Badge, type BadgeProps, BottomNav, BottomNavItem, type BottomNavProps, BottomNavSpacer, Box, type BoxProps, Breadcrumbs, type BreadcrumbsProps, Button, type ButtonProps, Card, CardHeader, CardMedia, type CardMediaProps, type CardProps, Checkbox, type CheckboxProps, type Crumb, Dialog, DialogActions, DialogBody, type DialogProps, Field, type FieldContextValue, type FieldProps, Heading, type HeadingProps, Icon, type IconProps, Input, type InputProps, type MarginProps, type Placement, Popover, type PopoverProps, type PresenceState, Radio, RadioGroup, type RadioGroupProps, type RadioProps, SegmentedControl, type SegmentedControlProps, type SegmentedOption, Select, type SelectProps, Slider, type SliderProps, SliderValue, Stack, type StackProps, Switch, type SwitchProps, Tab, TabList, type TabListProps, TabPanel, type TabPanelProps, type TabProps, Tabs, type TabsProps, Text, type TextProps, Textarea, type TextareaProps, ThemeScope, type ThemeScopeProps, type ToastOptions, ToastProvider, type ToastProviderProps, type ToastTone, Tooltip, type TooltipProps, cx, splitSprinkles, useDisclosure, useField, usePresence, useToast };
|
package/dist/index.js
CHANGED
|
@@ -6,15 +6,20 @@ import { Stack } from "./components/box/stack.js";
|
|
|
6
6
|
import { Button } from "./components/button/button.js";
|
|
7
7
|
import { Card, CardHeader } from "./components/card/card.js";
|
|
8
8
|
import { CardMedia } from "./components/card/card-media.js";
|
|
9
|
-
import { usePresence } from "./hooks/use-presence.js";
|
|
10
9
|
import { Icon } from "./components/icon/icon.js";
|
|
10
|
+
import { Checkbox, Radio, RadioGroup, Switch } from "./components/choice/choice.js";
|
|
11
|
+
import { usePresence } from "./hooks/use-presence.js";
|
|
11
12
|
import { Dialog, DialogActions, DialogBody } from "./components/dialog/dialog.js";
|
|
12
13
|
import { useField } from "./components/field/field-context.js";
|
|
13
14
|
import { Field } from "./components/field/field.js";
|
|
14
|
-
import { Input } from "./components/input/input.js";
|
|
15
|
+
import { Input, Textarea } from "./components/input/input.js";
|
|
16
|
+
import { Tab, TabList, TabPanel, Tabs } from "./components/navigation/tabs.js";
|
|
17
|
+
import { BottomNav, BottomNavItem, BottomNavSpacer, Breadcrumbs, SegmentedControl } from "./components/navigation/nav.js";
|
|
15
18
|
import { Popover, Tooltip } from "./components/popover/popover.js";
|
|
19
|
+
import { Select } from "./components/select/select.js";
|
|
20
|
+
import { Slider, SliderValue } from "./components/slider/slider.js";
|
|
16
21
|
import { Heading, Text } from "./components/text/text.js";
|
|
17
22
|
import { ToastProvider, useToast } from "./components/toast/toast.js";
|
|
18
23
|
import { cx } from "./utils/cx.js";
|
|
19
24
|
import { useDisclosure } from "./hooks/use-disclosure.js";
|
|
20
|
-
export { Avatar, AvatarGroup, Badge, Box, Button, Card, CardHeader, CardMedia, Dialog, DialogActions, DialogBody, Field, Heading, Icon, Input, Popover, Stack, Text, ThemeScope, ToastProvider, Tooltip, cx, splitSprinkles, useDisclosure, useField, usePresence, useToast };
|
|
25
|
+
export { Avatar, AvatarGroup, Badge, BottomNav, BottomNavItem, BottomNavSpacer, Box, Breadcrumbs, Button, Card, CardHeader, CardMedia, Checkbox, Dialog, DialogActions, DialogBody, Field, Heading, Icon, Input, Popover, Radio, RadioGroup, SegmentedControl, Select, Slider, SliderValue, Stack, Switch, Tab, TabList, TabPanel, Tabs, Text, Textarea, ThemeScope, ToastProvider, Tooltip, cx, splitSprinkles, useDisclosure, useField, usePresence, useToast };
|