@box-kite/react 1.0.0 → 2.0.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/.claude/rules/box-kite-rules.md +23 -1
- package/.claude/skills/box-kite/SKILL.md +134 -427
- package/.claude/skills/box-kite/references/components.md +235 -0
- package/.claude/skills/box-kite/references/extending.md +42 -0
- package/.claude/skills/box-kite/references/patterns.md +27 -0
- package/.claude/skills/box-kite/references/styling.md +222 -0
- package/.cursor/rules/box-kite.mdc +73 -0
- package/AGENTS.md +102 -0
- package/BOX_AI_CONTEXT.md +1124 -153
- package/BOX_KITE_AI_CONTEXT.md +1124 -153
- package/README.md +36 -2
- package/a11y.cjs +1 -1
- package/a11y.d.ts +1 -1
- package/a11y.mjs +3 -2
- package/anchor.cjs +1 -0
- package/anchor.d.ts +14 -0
- package/anchor.mjs +3 -0
- package/behavior.cjs +1 -1
- package/behavior.mjs +118 -136
- package/box.cjs +1 -1
- package/box.mjs +1 -1
- package/client.cjs +1 -1
- package/client.mjs +15 -14
- package/components/accordion.cjs +1 -0
- package/components/accordion.d.ts +114 -0
- package/components/accordion.mjs +251 -0
- package/components/button.cjs +1 -1
- package/components/button.d.ts +3 -0
- package/components/button.mjs +1 -1
- package/components/chart.cjs +1 -1
- package/components/chart.d.ts +2 -1
- package/components/chart.mjs +159 -184
- package/components/checkbox.cjs +1 -1
- package/components/checkbox.d.ts +8 -0
- package/components/checkbox.mjs +1 -1
- package/components/combobox/comboboxChips.d.ts +21 -0
- package/components/combobox/comboboxListbox.d.ts +47 -0
- package/components/combobox.cjs +1 -0
- package/components/combobox.d.ts +121 -0
- package/components/combobox.mjs +563 -0
- package/components/dataGrid/components/dataGridAggregateValue.d.ts +10 -0
- package/components/dataGrid/components/dataGridCell.d.ts +2 -1
- package/components/dataGrid/components/dataGridCellEditor.d.ts +15 -0
- package/components/dataGrid/components/dataGridCellPlaceholder.d.ts +14 -0
- package/components/dataGrid/components/dataGridCellTree.d.ts +16 -0
- package/components/dataGrid/components/dataGridDataSourceError.d.ts +12 -0
- package/components/dataGrid/components/dataGridExport.d.ts +10 -0
- package/components/dataGrid/components/dataGridFooter.d.ts +11 -0
- package/components/dataGrid/contracts/dataGridContract.d.ts +474 -16
- package/components/dataGrid/export/gridExport.d.ts +10 -0
- package/components/dataGrid/gridNavigationContext.d.ts +9 -1
- package/components/dataGrid/models/aggregateCellModel.d.ts +34 -0
- package/components/dataGrid/models/aggregationModel.d.ts +32 -0
- package/components/dataGrid/models/cellKeys.d.ts +11 -0
- package/components/dataGrid/models/cellModel.d.ts +27 -1
- package/components/dataGrid/models/columnModel.d.ts +12 -2
- package/components/dataGrid/models/dataSourceModel.d.ts +177 -0
- package/components/dataGrid/models/editModel.d.ts +77 -0
- package/components/dataGrid/models/exportModel.d.ts +51 -0
- package/components/dataGrid/models/gridModel.d.ts +108 -21
- package/components/dataGrid/models/groupRowCellModel.d.ts +11 -3
- package/components/dataGrid/models/groupRowModel.d.ts +22 -2
- package/components/dataGrid/models/rowModel.d.ts +13 -1
- package/components/dataGrid/models/sourceGroupRowModel.d.ts +45 -0
- package/components/dataGrid/models/sourceLevel.d.ts +71 -0
- package/components/dataGrid/models/sourceRowModel.d.ts +29 -0
- package/components/dataGrid/models/sourceTreeRowModel.d.ts +23 -0
- package/components/dataGrid/models/treeModel.d.ts +94 -0
- package/components/dataGrid/models/treeRow.d.ts +22 -0
- package/components/dataGrid/models/treeRowModel.d.ts +50 -0
- package/components/dataGrid.cjs +1 -1
- package/components/dataGrid.d.ts +4 -2
- package/components/dataGrid.mjs +4484 -2755
- package/components/dialog.cjs +1 -0
- package/components/dialog.d.ts +151 -0
- package/components/dialog.mjs +223 -0
- package/components/dropdown.cjs +1 -1
- package/components/dropdown.d.ts +30 -0
- package/components/dropdown.mjs +256 -244
- package/components/icon.cjs +1 -1
- package/components/icon.d.ts +2 -1
- package/components/icon.mjs +3 -3
- package/components/menu.cjs +1 -0
- package/components/menu.d.ts +234 -0
- package/components/menu.mjs +422 -0
- package/components/overlay.cjs +1 -1
- package/components/overlay.d.ts +30 -26
- package/components/overlay.mjs +45 -75
- package/components/popover.cjs +1 -0
- package/components/popover.d.ts +100 -0
- package/components/popover.mjs +69 -0
- package/components/presence.d.ts +6 -0
- package/components/progress.cjs +1 -0
- package/components/progress.d.ts +47 -0
- package/components/progress.mjs +28 -0
- package/components/radioButton.cjs +1 -1
- package/components/radioButton.d.ts +8 -0
- package/components/radioButton.mjs +1 -1
- package/components/radioGroup.cjs +1 -1
- package/components/radioGroup.d.ts +15 -2
- package/components/radioGroup.mjs +34 -30
- package/components/select.d.ts +9 -0
- package/components/semantics.cjs +1 -1
- package/components/semantics.d.ts +33 -28
- package/components/semantics.mjs +3 -3
- package/components/slider.cjs +1 -0
- package/components/slider.d.ts +98 -0
- package/components/slider.mjs +250 -0
- package/components/svg.cjs +1 -1
- package/components/svg.d.ts +25 -23
- package/components/svg.mjs +3 -3
- package/components/switch.cjs +1 -1
- package/components/switch.d.ts +9 -0
- package/components/switch.mjs +1 -1
- package/components/tabs.cjs +1 -0
- package/components/tabs.d.ts +87 -0
- package/components/tabs.mjs +324 -0
- package/components/textarea.cjs +1 -1
- package/components/textarea.d.ts +14 -0
- package/components/textarea.mjs +1 -1
- package/components/textbox.cjs +1 -1
- package/components/textbox.d.ts +12 -0
- package/components/textbox.mjs +1 -1
- package/components/toaster.cjs +1 -0
- package/components/toaster.d.ts +106 -0
- package/components/toaster.mjs +295 -0
- package/components/tooltip.cjs +1 -1
- package/components/tooltip.d.ts +39 -4
- package/components/tooltip.mjs +56 -54
- package/docs/a11y.md +199 -0
- package/docs/anchor.md +139 -0
- package/docs/components.md +48 -0
- package/docs/index.md +11 -0
- package/docs/props.md +1777 -0
- package/effects.cjs +1 -1
- package/effects.mjs +1 -1
- package/gridExport.cjs +2 -0
- package/gridExport.mjs +244 -0
- package/identity.cjs +1 -0
- package/identity.mjs +12 -0
- package/keyboard.cjs +1 -0
- package/keyboard.mjs +30 -0
- package/layer.cjs +1 -0
- package/layer.mjs +127 -0
- package/motion.cjs +1 -1
- package/motion.mjs +1 -1
- package/package.json +134 -10
- package/placement.cjs +1 -0
- package/placement.mjs +180 -0
- package/platform.cjs +1 -1
- package/platform.mjs +18 -5
- package/react/anchor/useAnchorPosition.d.ts +79 -0
- package/react/dialog/useScrollLock.d.ts +12 -0
- package/react/hooks/usePortalContainer.d.ts +6 -1
- package/react/hooks/useVirtualization.d.ts +24 -35
- package/react/popover/usePopoverLayer.d.ts +87 -0
- package/react-shared.cjs +1 -1
- package/react-shared.mjs +19 -2
- package/rsc.cjs +1 -1
- package/rsc.mjs +1 -1
- package/utils/accordion/accordionUtils.d.ts +48 -0
- package/utils/anchor/anchorUtils.d.ts +79 -0
- package/utils/array/lazyList.d.ts +10 -0
- package/utils/chart/chartPalette.d.ts +15 -0
- package/utils/chart/chartUtils.d.ts +2 -8
- package/utils/combobox/comboboxUtils.d.ts +89 -0
- package/utils/dom/domUtils.d.ts +6 -0
- package/utils/environment/environmentUtils.d.ts +10 -0
- package/utils/export/csvUtils.d.ts +23 -0
- package/utils/export/downloadUtils.d.ts +12 -0
- package/utils/export/xlsxUtils.d.ts +56 -0
- package/utils/export/zipUtils.d.ts +26 -0
- package/utils/keyboard/typeaheadUtils.d.ts +31 -0
- package/utils/menu/menuUtils.d.ts +25 -0
- package/utils/slider/sliderUtils.d.ts +67 -0
- package/utils/tabs/tabsUtils.d.ts +75 -0
- package/utils/toast/toastStore.d.ts +73 -0
- package/utils/virtual/virtualUtils.d.ts +47 -0
- /package/react/{a11y → identity}/useIdentifier.d.ts +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use client";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});const e=require("../platform.cjs"),t=require("../box.cjs"),n=require("../behavior.cjs");let r=require("react"),i=require("react/jsx-runtime");var a;(function(e){function t(e){let t=String(Math.abs(e));if(t.includes(`e`))return 12;let n=t.indexOf(`.`);return n===-1?0:t.length-n-1}e.decimals=t;function n(e,t){return Number(e.toFixed(Math.min(t,15)))}function r(e,t,n){return Math.min(Math.max(e,t),n)}e.clamp=r;function i(e,i){let{min:a,max:o,step:s}=i,c=r(e,a,o);return s>0?r(n(a+Math.round((c-a)/s)*s,t(s)+t(a)),a,o):c}e.snap=i;function a(e,t,n){return n<=t?0:(r(e,t,n)-t)*(100/(n-t))}e.percent=a;function o(e,t,n){return`${Math.round(a(e,t,n)*100)/100}%`}e.percentage=o;function s(e){return typeof e==`number`?[e]:[...e]}e.thumbs=s;function c(e,t){return typeof e==`number`?t[0]:[...t]}e.shaped=c;function l(e,t,n,a){let o=t>0?e[t-1]:a.min,s=t<e.length-1?e[t+1]:a.max,c=[...e];return c[t]=r(i(n,a),o,s),c}e.move=l;function u(e,t){return e.length===t.length&&e.every((e,n)=>e===t[n])}e.same=u;function d(e,t){let n=0,r=1/0;return e.forEach((e,i)=>{let a=Math.abs(e-t);a<=r&&(n=i,r=a)}),n}e.nearest=d;function f(e,t,n,r,i){let a=r===`vertical`?e.height===0?0:(e.bottom-n)/e.height:e.width===0?0:i?(e.right-t)/e.width:(t-e.left)/e.width;return Math.min(Math.max(a,0),1)}e.valueAt=f;function p(e,t=!1){if(e===`Home`)return{kind:`edge`,delta:-1};if(e===`End`)return{kind:`edge`,delta:1};if(e===`PageUp`)return{kind:`page`,delta:1};if(e===`PageDown`)return{kind:`page`,delta:-1};if(e===`ArrowUp`)return{kind:`step`,delta:1};if(e===`ArrowDown`)return{kind:`step`,delta:-1};if(e===`ArrowRight`)return{kind:`step`,delta:t?-1:1};if(e===`ArrowLeft`)return{kind:`step`,delta:t?1:-1}}e.moveFor=p;function m(e,t,n,r){if(t.kind===`edge`)return t.delta>0?n.max:n.min;let i=t.kind===`page`?r:n.step;return e+t.delta*i}e.moved=m})(a||={});var o=a,s=`data-index`;function c(e,t,n){return{min:e,max:t,step:n}}function l(e,t){return t?{insetBlockEnd:e}:{insetInlineStart:e}}function u(e,t,n){let r=e.length>1?Math.min(...e):t.min,i=Math.max(...e),a=o.percent(r,t.min,t.max),s=`${Math.round((o.percent(i,t.min,t.max)-a)*100)/100}%`;return n?{insetBlockEnd:`${Math.round(a*100)/100}%`,blockSize:s}:{insetInlineStart:`${Math.round(a*100)/100}%`,inlineSize:s}}function d(a){let{value:d,defaultValue:f,onValueChange:p,onValueCommit:m,min:h=0,max:g=100,step:_=1,largeStep:v=_*10,orientation:y=`horizontal`,disabled:b=!1,label:x,labelledBy:S,thumbLabels:C,format:w,name:T,props:E,...D}=a,O=(0,r.useRef)(null),k=(0,r.useRef)(null),A=(0,r.useRef)(null),j=(0,r.useRef)(!1),[M,N]=(0,r.useState)(!1),[P,F]=n.i({value:d,defaultValue:f??h,onChange:p}),I=c(h,g,_),L=y===`vertical`,R=o.thumbs(P),z=n.o(P),B=n.a(m),V=n.a((e,t)=>{F(t=>o.same(o.thumbs(t),e)?t:o.shaped(t,e),t)}),H=t=>{let n=k.current;if(!n)return;let r=o.valueAt(n.getBoundingClientRect(),t.clientX,t.clientY,y,e.u(n));return h+r*(g-h)},U=e=>O.current?.querySelectorAll(`[role="slider"]`)[e],W=n.a(e=>{if(b||e.button!==0||e.defaultPrevented)return;let t=H(e);if(t===void 0)return;let n=o.thumbs(z.current),r=o.nearest(n,t);A.current=r,e.preventDefault(),e.currentTarget.setPointerCapture?.(e.pointerId),U(r)?.focus(),V(o.move(n,r,t,I),{reason:`pointer`,event:e})}),G=n.a(e=>{let t=A.current;if(t===null)return;let n=H(e);n!==void 0&&(N(!0),V(o.move(o.thumbs(z.current),t,n,I),{reason:`pointer`,event:e}))}),K=n.a(e=>{A.current!==null&&(A.current=null,N(!1),e.currentTarget.releasePointerCapture?.(e.pointerId),B(z.current,{reason:`pointer`,event:e}))}),q=n.a(t=>{if(b||t.defaultPrevented)return;let n=t.target?.closest(`[role="slider"]`),r=Number(n?.getAttribute(s)??-1);if(!n||r<0)return;let i=o.moveFor(t.key,e.u(n));if(!i)return;t.preventDefault(),j.current=!0,N(!0);let a=o.thumbs(z.current);V(o.move(a,r,o.moved(a[r],i,I,v),I),{reason:`keyboard`,event:t})}),J=n.a(e=>{j.current&&(j.current=!1,N(!1),B(z.current,{reason:`keyboard`,event:e}))}),Y=R.length>1;return(0,i.jsxs)(t.default,{ref:O,component:`slider`,...D,variant:[D.variant,{vertical:L,disabled:b}],props:{role:Y?`group`:void 0,"aria-label":Y?x:void 0,"aria-labelledby":Y?S:void 0,...E,onPointerDown:W,onPointerMove:G,onPointerUp:K,onPointerCancel:K,onKeyDown:q,onKeyUp:J},children:[(0,i.jsx)(t.default,{ref:k,component:`slider.track`,variant:{vertical:L},children:(0,i.jsx)(t.default,{component:`slider.fill`,variant:{vertical:L,tracking:M},style:u(R,I,L)})}),R.map((e,n)=>(0,i.jsx)(t.default,{component:`slider.thumb`,variant:{vertical:L,disabled:b,tracking:M},style:l(o.percentage(e,h,g),L),props:{role:`slider`,tabIndex:b?-1:0,"aria-valuemin":h,"aria-valuemax":g,"aria-valuenow":e,"aria-valuetext":w?.(e),"aria-orientation":y,"aria-label":C?.[n]??(Y?void 0:x),"aria-labelledby":C?.[n]||Y?void 0:S,"aria-disabled":b||void 0,[s]:n}},n)),T!==void 0&&R.map((e,t)=>(0,i.jsx)(`input`,{type:`hidden`,name:T,value:e,readOnly:!0},t))]})}var f=d;f.displayName=`Slider`,exports.default=f;
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { BoxProps } from '../box';
|
|
2
|
+
import { ChangeHandler } from '../react/a11y/useControllableState';
|
|
3
|
+
import { ComponentsAndVariants } from '@box-kite/core/types';
|
|
4
|
+
import { SliderOrientation } from '../utils/slider/sliderUtils';
|
|
5
|
+
export type { SliderOrientation };
|
|
6
|
+
/** What a slider takes and reports: one number, or one per thumb. The shape it is given is the shape it gives back. */
|
|
7
|
+
export type SliderValue = number | number[];
|
|
8
|
+
/** Why the value changed. A drag and the arrow keys want different things from a consumer — a live preview against a request. */
|
|
9
|
+
export type SliderReason = 'pointer' | 'keyboard';
|
|
10
|
+
type SliderBoxProps<TKey extends keyof ComponentsAndVariants> = Omit<BoxProps<'div', TKey>, 'onChange' | 'disabled'>;
|
|
11
|
+
export interface SliderProps<TKey extends keyof ComponentsAndVariants = 'slider', TValue extends SliderValue = number> extends SliderBoxProps<TKey> {
|
|
12
|
+
/** Controlled value. A number is one thumb and an array is one per entry; leave it out and the widget owns it. */
|
|
13
|
+
value?: TValue;
|
|
14
|
+
/** What it starts at, and what decides how many thumbs there are. Default `min`. */
|
|
15
|
+
defaultValue?: TValue;
|
|
16
|
+
/** Fires on every step of a drag and every arrow key, in the shape the value was given in. */
|
|
17
|
+
onValueChange?: ChangeHandler<TValue, SliderReason>;
|
|
18
|
+
/** Fires once when the interaction ends — the place for a request the live value is too noisy for. */
|
|
19
|
+
onValueCommit?: ChangeHandler<TValue, SliderReason>;
|
|
20
|
+
/** The bottom of the range. Default `0`. */
|
|
21
|
+
min?: number;
|
|
22
|
+
/** The top of the range. Default `100`. */
|
|
23
|
+
max?: number;
|
|
24
|
+
/** The grid every value lands on. Default `1`; `0` is a continuous slider. */
|
|
25
|
+
step?: number;
|
|
26
|
+
/** What Page Up and Page Down move by. Default ten steps. */
|
|
27
|
+
largeStep?: number;
|
|
28
|
+
/** Which way the thumbs run. Default `horizontal`, whose arrows follow the reading order. */
|
|
29
|
+
orientation?: SliderOrientation;
|
|
30
|
+
/** Not adjustable, by pointer or by key. It is `aria-disabled`, so the thumb keeps its place in the tab order and stays readable. */
|
|
31
|
+
disabled?: boolean;
|
|
32
|
+
/** What the slider is called. On one thumb it names the thumb; on several it names the group around them. */
|
|
33
|
+
label?: string;
|
|
34
|
+
/** The same, naming an element that already says it. */
|
|
35
|
+
labelledBy?: string;
|
|
36
|
+
/** One name per thumb — "Minimum", "Maximum". A range wants them: `label` names the group, not the thumbs. */
|
|
37
|
+
thumbLabels?: readonly string[];
|
|
38
|
+
/** The value as it should be read out, when the number alone is not it: a currency, a date, a rating. */
|
|
39
|
+
format?: (value: number) => string;
|
|
40
|
+
/** What the value submits under. One hidden input per thumb, so a range posts two values of that name. */
|
|
41
|
+
name?: string;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* A value chosen by dragging a thumb along a track.
|
|
45
|
+
* Pattern: https://www.w3.org/WAI/ARIA/apg/patterns/slider/ and .../slider-multithumb/
|
|
46
|
+
*
|
|
47
|
+
* ```tsx
|
|
48
|
+
* <Slider label="Volume" defaultValue={40} onValueChange={(value) => setVolume(value)} />
|
|
49
|
+
* <Slider label="Price" defaultValue={[20, 80]} thumbLabels={['Lowest', 'Highest']} />
|
|
50
|
+
* ```
|
|
51
|
+
*
|
|
52
|
+
* **A number in is a number out.** `defaultValue={40}` makes a one-thumb slider whose `onValueChange`
|
|
53
|
+
* hands back a `number`; `defaultValue={[20, 80]}` makes a range whose handler takes a `number[]`. The
|
|
54
|
+
* number of thumbs is the value's own shape, so there is no second prop saying which kind this is.
|
|
55
|
+
*
|
|
56
|
+
* **This is not `<input type="range">`, and that is the one place the platform loses.** A range input
|
|
57
|
+
* cannot hold two thumbs, and its track and thumb are vendor pseudo-elements (`::-webkit-slider-thumb`)
|
|
58
|
+
* that no typed prop can reach — so a styled one is a rewrite of the parts, at which point the native
|
|
59
|
+
* element is only the keyboard. `name` still submits: a hidden input per thumb, so a form posts the
|
|
60
|
+
* value whether or not JavaScript ran the drag.
|
|
61
|
+
*
|
|
62
|
+
* **The position is an inline style, deliberately.** Everything a slider paints is a shared class except
|
|
63
|
+
* where its thumbs are — that is a per-frame value, and a class for it would be a rule per frame of a
|
|
64
|
+
* drag, never freed. It is the exception `useAnchorPosition`'s anchor name and the travelling tab
|
|
65
|
+
* indicator already take, and the reason a `ProgressRing` can round its fraction into a class where this
|
|
66
|
+
* cannot: nobody drags a ring.
|
|
67
|
+
*
|
|
68
|
+
* **It mirrors for free.** The fill and the thumbs are placed with `inset-inline-start`, so a
|
|
69
|
+
* right-to-left page draws the minimum on the right with no second stylesheet. The half that is not free
|
|
70
|
+
* is the keyboard, which is why the sideways arrows swap and Up and Down never do.
|
|
71
|
+
*
|
|
72
|
+
* **A press travels; a nudge does not.** A press on the track is the one move the eye has to follow, so
|
|
73
|
+
* the thumb animates the whole way. Every other move — a drag, an arrow key, a held arrow — is the
|
|
74
|
+
* `tracking` variant instead: 60ms `ease-out` on both the thumb and the fill, which must both carry it
|
|
75
|
+
* or they come apart (#144). Short rather than *off*, because off is exact and steps — a 1-in-100 slider
|
|
76
|
+
* moves 3.2px at a time on a 320px track. **Eased out rather than linear or eased**: a repeat restarts
|
|
77
|
+
* the transition every 33ms, so only its first half is ever seen, and on this curve that half is the
|
|
78
|
+
* straight part — it glides while the key is held and still decelerates on the last transition, the one
|
|
79
|
+
* allowed to finish. Measured against linear, which rode **1.4 steps** behind the value and stopped at
|
|
80
|
+
* full speed, this rides 0.9 behind and lands at 0.6 of cruising (#146).
|
|
81
|
+
*
|
|
82
|
+
* @pattern https://www.w3.org/WAI/ARIA/apg/patterns/slider/
|
|
83
|
+
* @a11y Each thumb is a `role="slider"` carrying `aria-valuemin`, `aria-valuemax`, `aria-valuenow` and
|
|
84
|
+
* `aria-orientation`; `format` writes `aria-valuetext` for a value a bare number does not read as.
|
|
85
|
+
* @a11y A thumb has to be named, so `label` names the one on a single slider — and on a range it names
|
|
86
|
+
* the `role="group"` around the thumbs, where `thumbLabels` names them one at a time.
|
|
87
|
+
* @a11y `disabled` is `aria-disabled` rather than the attribute: a slider a reader cannot reach is a
|
|
88
|
+
* value they cannot read, and a div takes no `disabled` anyway.
|
|
89
|
+
* @keyboard Tab — Every thumb is its own tab stop, so a range is two of them.
|
|
90
|
+
* @keyboard Right / Up — One step towards the maximum. In a right-to-left page Left is the increase, and
|
|
91
|
+
* Up never changes: the block axis has no reading order.
|
|
92
|
+
* @keyboard Left / Down — One step towards the minimum.
|
|
93
|
+
* @keyboard PageUp / PageDown — `largeStep`, ten steps unless it says otherwise.
|
|
94
|
+
* @keyboard Home / End — The minimum and the maximum themselves, on or off the step grid.
|
|
95
|
+
*/
|
|
96
|
+
declare function SliderImpl<TKey extends keyof ComponentsAndVariants = 'slider', TValue extends SliderValue = number>(props: SliderProps<TKey, TValue>): import("react").JSX.Element;
|
|
97
|
+
declare const Slider: typeof SliderImpl;
|
|
98
|
+
export default Slider;
|
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { u as e } from "../platform.mjs";
|
|
3
|
+
import t from "../box.mjs";
|
|
4
|
+
import { a as n, i as r, o as i } from "../behavior.mjs";
|
|
5
|
+
import { useRef as a, useState as o } from "react";
|
|
6
|
+
import { jsx as s, jsxs as c } from "react/jsx-runtime";
|
|
7
|
+
//#region src/utils/slider/sliderUtils.ts
|
|
8
|
+
var l;
|
|
9
|
+
(function(e) {
|
|
10
|
+
function t(e) {
|
|
11
|
+
let t = String(Math.abs(e));
|
|
12
|
+
if (t.includes("e")) return 12;
|
|
13
|
+
let n = t.indexOf(".");
|
|
14
|
+
return n === -1 ? 0 : t.length - n - 1;
|
|
15
|
+
}
|
|
16
|
+
e.decimals = t;
|
|
17
|
+
function n(e, t) {
|
|
18
|
+
return Number(e.toFixed(Math.min(t, 15)));
|
|
19
|
+
}
|
|
20
|
+
function r(e, t, n) {
|
|
21
|
+
return Math.min(Math.max(e, t), n);
|
|
22
|
+
}
|
|
23
|
+
e.clamp = r;
|
|
24
|
+
function i(e, i) {
|
|
25
|
+
let { min: a, max: o, step: s } = i, c = r(e, a, o);
|
|
26
|
+
return s > 0 ? r(n(a + Math.round((c - a) / s) * s, t(s) + t(a)), a, o) : c;
|
|
27
|
+
}
|
|
28
|
+
e.snap = i;
|
|
29
|
+
function a(e, t, n) {
|
|
30
|
+
return n <= t ? 0 : (r(e, t, n) - t) * (100 / (n - t));
|
|
31
|
+
}
|
|
32
|
+
e.percent = a;
|
|
33
|
+
function o(e, t, n) {
|
|
34
|
+
return `${Math.round(a(e, t, n) * 100) / 100}%`;
|
|
35
|
+
}
|
|
36
|
+
e.percentage = o;
|
|
37
|
+
function s(e) {
|
|
38
|
+
return typeof e == "number" ? [e] : [...e];
|
|
39
|
+
}
|
|
40
|
+
e.thumbs = s;
|
|
41
|
+
function c(e, t) {
|
|
42
|
+
return typeof e == "number" ? t[0] : [...t];
|
|
43
|
+
}
|
|
44
|
+
e.shaped = c;
|
|
45
|
+
function l(e, t, n, a) {
|
|
46
|
+
let o = t > 0 ? e[t - 1] : a.min, s = t < e.length - 1 ? e[t + 1] : a.max, c = [...e];
|
|
47
|
+
return c[t] = r(i(n, a), o, s), c;
|
|
48
|
+
}
|
|
49
|
+
e.move = l;
|
|
50
|
+
function u(e, t) {
|
|
51
|
+
return e.length === t.length && e.every((e, n) => e === t[n]);
|
|
52
|
+
}
|
|
53
|
+
e.same = u;
|
|
54
|
+
function d(e, t) {
|
|
55
|
+
let n = 0, r = Infinity;
|
|
56
|
+
return e.forEach((e, i) => {
|
|
57
|
+
let a = Math.abs(e - t);
|
|
58
|
+
a <= r && (n = i, r = a);
|
|
59
|
+
}), n;
|
|
60
|
+
}
|
|
61
|
+
e.nearest = d;
|
|
62
|
+
function f(e, t, n, r, i) {
|
|
63
|
+
let a = r === "vertical" ? e.height === 0 ? 0 : (e.bottom - n) / e.height : e.width === 0 ? 0 : i ? (e.right - t) / e.width : (t - e.left) / e.width;
|
|
64
|
+
return Math.min(Math.max(a, 0), 1);
|
|
65
|
+
}
|
|
66
|
+
e.valueAt = f;
|
|
67
|
+
function p(e, t = !1) {
|
|
68
|
+
if (e === "Home") return {
|
|
69
|
+
kind: "edge",
|
|
70
|
+
delta: -1
|
|
71
|
+
};
|
|
72
|
+
if (e === "End") return {
|
|
73
|
+
kind: "edge",
|
|
74
|
+
delta: 1
|
|
75
|
+
};
|
|
76
|
+
if (e === "PageUp") return {
|
|
77
|
+
kind: "page",
|
|
78
|
+
delta: 1
|
|
79
|
+
};
|
|
80
|
+
if (e === "PageDown") return {
|
|
81
|
+
kind: "page",
|
|
82
|
+
delta: -1
|
|
83
|
+
};
|
|
84
|
+
if (e === "ArrowUp") return {
|
|
85
|
+
kind: "step",
|
|
86
|
+
delta: 1
|
|
87
|
+
};
|
|
88
|
+
if (e === "ArrowDown") return {
|
|
89
|
+
kind: "step",
|
|
90
|
+
delta: -1
|
|
91
|
+
};
|
|
92
|
+
if (e === "ArrowRight") return {
|
|
93
|
+
kind: "step",
|
|
94
|
+
delta: t ? -1 : 1
|
|
95
|
+
};
|
|
96
|
+
if (e === "ArrowLeft") return {
|
|
97
|
+
kind: "step",
|
|
98
|
+
delta: t ? 1 : -1
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
e.moveFor = p;
|
|
102
|
+
function m(e, t, n, r) {
|
|
103
|
+
if (t.kind === "edge") return t.delta > 0 ? n.max : n.min;
|
|
104
|
+
let i = t.kind === "page" ? r : n.step;
|
|
105
|
+
return e + t.delta * i;
|
|
106
|
+
}
|
|
107
|
+
e.moved = m;
|
|
108
|
+
})(l ||= {});
|
|
109
|
+
var u = l, d = "data-index";
|
|
110
|
+
function f(e, t, n) {
|
|
111
|
+
return {
|
|
112
|
+
min: e,
|
|
113
|
+
max: t,
|
|
114
|
+
step: n
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
function p(e, t) {
|
|
118
|
+
return t ? { insetBlockEnd: e } : { insetInlineStart: e };
|
|
119
|
+
}
|
|
120
|
+
function m(e, t, n) {
|
|
121
|
+
let r = e.length > 1 ? Math.min(...e) : t.min, i = Math.max(...e), a = u.percent(r, t.min, t.max), o = `${Math.round((u.percent(i, t.min, t.max) - a) * 100) / 100}%`;
|
|
122
|
+
return n ? {
|
|
123
|
+
insetBlockEnd: `${Math.round(a * 100) / 100}%`,
|
|
124
|
+
blockSize: o
|
|
125
|
+
} : {
|
|
126
|
+
insetInlineStart: `${Math.round(a * 100) / 100}%`,
|
|
127
|
+
inlineSize: o
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
function h(l) {
|
|
131
|
+
let { value: h, defaultValue: g, onValueChange: _, onValueCommit: v, min: y = 0, max: b = 100, step: x = 1, largeStep: S = x * 10, orientation: C = "horizontal", disabled: w = !1, label: T, labelledBy: E, thumbLabels: D, format: O, name: k, props: A, ...j } = l, M = a(null), N = a(null), P = a(null), F = a(!1), [I, L] = o(!1), [R, z] = r({
|
|
132
|
+
value: h,
|
|
133
|
+
defaultValue: g ?? y,
|
|
134
|
+
onChange: _
|
|
135
|
+
}), B = f(y, b, x), V = C === "vertical", H = u.thumbs(R), U = i(R), W = n(v), G = n((e, t) => {
|
|
136
|
+
z((t) => u.same(u.thumbs(t), e) ? t : u.shaped(t, e), t);
|
|
137
|
+
}), K = (t) => {
|
|
138
|
+
let n = N.current;
|
|
139
|
+
if (!n) return;
|
|
140
|
+
let r = u.valueAt(n.getBoundingClientRect(), t.clientX, t.clientY, C, e(n));
|
|
141
|
+
return y + r * (b - y);
|
|
142
|
+
}, q = (e) => M.current?.querySelectorAll("[role=\"slider\"]")[e], J = n((e) => {
|
|
143
|
+
if (w || e.button !== 0 || e.defaultPrevented) return;
|
|
144
|
+
let t = K(e);
|
|
145
|
+
if (t === void 0) return;
|
|
146
|
+
let n = u.thumbs(U.current), r = u.nearest(n, t);
|
|
147
|
+
P.current = r, e.preventDefault(), e.currentTarget.setPointerCapture?.(e.pointerId), q(r)?.focus(), G(u.move(n, r, t, B), {
|
|
148
|
+
reason: "pointer",
|
|
149
|
+
event: e
|
|
150
|
+
});
|
|
151
|
+
}), Y = n((e) => {
|
|
152
|
+
let t = P.current;
|
|
153
|
+
if (t === null) return;
|
|
154
|
+
let n = K(e);
|
|
155
|
+
n !== void 0 && (L(!0), G(u.move(u.thumbs(U.current), t, n, B), {
|
|
156
|
+
reason: "pointer",
|
|
157
|
+
event: e
|
|
158
|
+
}));
|
|
159
|
+
}), X = n((e) => {
|
|
160
|
+
P.current !== null && (P.current = null, L(!1), e.currentTarget.releasePointerCapture?.(e.pointerId), W(U.current, {
|
|
161
|
+
reason: "pointer",
|
|
162
|
+
event: e
|
|
163
|
+
}));
|
|
164
|
+
}), Z = n((t) => {
|
|
165
|
+
if (w || t.defaultPrevented) return;
|
|
166
|
+
let n = t.target?.closest("[role=\"slider\"]"), r = Number(n?.getAttribute(d) ?? -1);
|
|
167
|
+
if (!n || r < 0) return;
|
|
168
|
+
let i = u.moveFor(t.key, e(n));
|
|
169
|
+
if (!i) return;
|
|
170
|
+
t.preventDefault(), F.current = !0, L(!0);
|
|
171
|
+
let a = u.thumbs(U.current);
|
|
172
|
+
G(u.move(a, r, u.moved(a[r], i, B, S), B), {
|
|
173
|
+
reason: "keyboard",
|
|
174
|
+
event: t
|
|
175
|
+
});
|
|
176
|
+
}), Q = n((e) => {
|
|
177
|
+
F.current && (F.current = !1, L(!1), W(U.current, {
|
|
178
|
+
reason: "keyboard",
|
|
179
|
+
event: e
|
|
180
|
+
}));
|
|
181
|
+
}), $ = H.length > 1;
|
|
182
|
+
return /* @__PURE__ */ c(t, {
|
|
183
|
+
ref: M,
|
|
184
|
+
component: "slider",
|
|
185
|
+
...j,
|
|
186
|
+
variant: [j.variant, {
|
|
187
|
+
vertical: V,
|
|
188
|
+
disabled: w
|
|
189
|
+
}],
|
|
190
|
+
props: {
|
|
191
|
+
role: $ ? "group" : void 0,
|
|
192
|
+
"aria-label": $ ? T : void 0,
|
|
193
|
+
"aria-labelledby": $ ? E : void 0,
|
|
194
|
+
...A,
|
|
195
|
+
onPointerDown: J,
|
|
196
|
+
onPointerMove: Y,
|
|
197
|
+
onPointerUp: X,
|
|
198
|
+
onPointerCancel: X,
|
|
199
|
+
onKeyDown: Z,
|
|
200
|
+
onKeyUp: Q
|
|
201
|
+
},
|
|
202
|
+
children: [
|
|
203
|
+
/* @__PURE__ */ s(t, {
|
|
204
|
+
ref: N,
|
|
205
|
+
component: "slider.track",
|
|
206
|
+
variant: { vertical: V },
|
|
207
|
+
children: /* @__PURE__ */ s(t, {
|
|
208
|
+
component: "slider.fill",
|
|
209
|
+
variant: {
|
|
210
|
+
vertical: V,
|
|
211
|
+
tracking: I
|
|
212
|
+
},
|
|
213
|
+
style: m(H, B, V)
|
|
214
|
+
})
|
|
215
|
+
}),
|
|
216
|
+
H.map((e, n) => /* @__PURE__ */ s(t, {
|
|
217
|
+
component: "slider.thumb",
|
|
218
|
+
variant: {
|
|
219
|
+
vertical: V,
|
|
220
|
+
disabled: w,
|
|
221
|
+
tracking: I
|
|
222
|
+
},
|
|
223
|
+
style: p(u.percentage(e, y, b), V),
|
|
224
|
+
props: {
|
|
225
|
+
role: "slider",
|
|
226
|
+
tabIndex: w ? -1 : 0,
|
|
227
|
+
"aria-valuemin": y,
|
|
228
|
+
"aria-valuemax": b,
|
|
229
|
+
"aria-valuenow": e,
|
|
230
|
+
"aria-valuetext": O?.(e),
|
|
231
|
+
"aria-orientation": C,
|
|
232
|
+
"aria-label": D?.[n] ?? ($ ? void 0 : T),
|
|
233
|
+
"aria-labelledby": D?.[n] || $ ? void 0 : E,
|
|
234
|
+
"aria-disabled": w || void 0,
|
|
235
|
+
[d]: n
|
|
236
|
+
}
|
|
237
|
+
}, n)),
|
|
238
|
+
k !== void 0 && H.map((e, t) => /* @__PURE__ */ s("input", {
|
|
239
|
+
type: "hidden",
|
|
240
|
+
name: k,
|
|
241
|
+
value: e,
|
|
242
|
+
readOnly: !0
|
|
243
|
+
}, t))
|
|
244
|
+
]
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
var g = h;
|
|
248
|
+
g.displayName = "Slider";
|
|
249
|
+
//#endregion
|
|
250
|
+
export { g as default };
|
package/components/svg.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("../rolldown-runtime.cjs"),t=require("../react-shared.cjs");let n=require("react"),r=require("react/jsx-runtime"),i=require("@box-kite/react");i=e.t(i,1);function a(e,t){let{props:n,...r}=e,i=r,a;for(let e of t)e in i&&((a??={})[e]=i[e],delete i[e]);return{styleProps:i,tagProps:a?{...n,...a}:n}}function o(e,o=[],s){let c=o,l=(0,n.forwardRef)((t,n)=>{let{styleProps:o,tagProps:s}=a(t,c);return(0,r.jsx)(i.default,{tag:e,ref:n,component:e,...o,props:s})});return l.displayName=s??t.
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("../rolldown-runtime.cjs"),t=require("../react-shared.cjs");let n=require("react"),r=require("react/jsx-runtime"),i=require("@box-kite/react");i=e.t(i,1);function a(e,t){let{props:n,...r}=e,i=r,a;for(let e of t)e in i&&((a??={})[e]=i[e],delete i[e]);return{styleProps:i,tagProps:a?{...n,...a}:n}}function o(e,o=[],s){let c=o,l=(0,n.forwardRef)((t,n)=>{let{styleProps:o,tagProps:s}=a(t,c);return(0,r.jsx)(i.default,{tag:e,ref:n,component:e,...o,props:s})});return l.displayName=s??t.a.capitalize(e),t.c(l),l}var s=`http://www.w3.org/2000/svg`,c=[`viewBox`,`preserveAspectRatio`,`width`,`height`];function l(e,n){let{label:o,...l}=e,{styleProps:u,tagProps:d}=a(l,c);return(0,r.jsx)(i.default,{tag:`svg`,ref:n,component:`svg`,...u,props:{xmlns:s,...t.o(o,d),...d}})}var u=t.c((0,n.forwardRef)(l));u.displayName=`Svg`;var d=o(`g`,[`transform`]),f=o(`defs`),p=o(`path`,[`d`,`transform`,`pathLength`]),m=o(`circle`,[`transform`,`pathLength`]),h=o(`ellipse`,[`transform`,`pathLength`]),g=o(`rect`,[`width`,`height`,`transform`,`pathLength`]),_=o(`line`,[`x1`,`y1`,`x2`,`y2`,`transform`,`pathLength`]),v=o(`polyline`,[`points`,`transform`,`pathLength`]),y=o(`polygon`,[`points`,`transform`,`pathLength`]),b=o(`text`,[`x`,`y`,`dx`,`dy`,`textLength`,`lengthAdjust`,`transform`],`SvgText`),x=o(`tspan`,[`x`,`y`,`dx`,`dy`,`textLength`,`lengthAdjust`],`TSpan`),S=o(`linearGradient`,[`x1`,`y1`,`x2`,`y2`,`gradientUnits`,`gradientTransform`,`spreadMethod`]),C=o(`radialGradient`,[`cx`,`cy`,`r`,`fx`,`fy`,`gradientUnits`,`gradientTransform`,`spreadMethod`]),w=o(`stop`,[`offset`,`stopColor`,`stopOpacity`]),T=o(`clipPath`,[`clipPathUnits`,`transform`]),E=o(`mask`,[`maskUnits`,`maskContentUnits`,`x`,`y`,`width`,`height`]),D=o(`use`,[`href`,`width`,`height`,`transform`]),O=o(`symbol`,[`viewBox`,`preserveAspectRatio`,`x`,`y`,`width`,`height`],`SvgSymbol`),k=o(`marker`,[`markerWidth`,`markerHeight`,`refX`,`refY`,`orient`,`markerUnits`,`viewBox`]);exports.Circle=m,exports.ClipPath=T,exports.Defs=f,exports.Ellipse=h,exports.G=d,exports.Line=_,exports.LinearGradient=S,exports.Marker=k,exports.Mask=E,exports.Path=p,exports.Polygon=y,exports.Polyline=v,exports.RadialGradient=C,exports.Rect=g,exports.Stop=w,exports.Svg=u,exports.SvgSymbol=O,exports.SvgText=b,exports.TSpan=x,exports.Use=D;
|
package/components/svg.d.ts
CHANGED
|
@@ -13,7 +13,7 @@ import { ComponentsAndVariants } from '@box-kite/core/types';
|
|
|
13
13
|
type Attribute<TTag extends keyof React.JSX.IntrinsicElements> = keyof React.JSX.IntrinsicElements[TTag];
|
|
14
14
|
/** Box's props for the tag, minus the names this element claims as attributes, plus those attributes. */
|
|
15
15
|
type SvgElementProps<TTag extends keyof React.JSX.IntrinsicElements, TAttribute extends Attribute<TTag>, TKey extends keyof ComponentsAndVariants> = Omit<BoxProps<TTag, TKey>, 'tag' | TAttribute> & Pick<React.JSX.IntrinsicElements[TTag], TAttribute>;
|
|
16
|
-
type SvgElementType<TTag extends keyof React.JSX.IntrinsicElements, TAttribute extends Attribute<TTag
|
|
16
|
+
type SvgElementType<TTag extends keyof React.JSX.IntrinsicElements, TAttribute extends Attribute<TTag>> = <TKey extends keyof ComponentsAndVariants = never>(props: SvgElementProps<TTag, TAttribute, TKey> & RefAttributes<ExtractElementFromTag<TTag>>) => React.ReactNode;
|
|
17
17
|
interface SvgOwnProps {
|
|
18
18
|
/** The coordinate system every number inside the drawing is measured in — `"0 0 24 24"`. */
|
|
19
19
|
viewBox?: string;
|
|
@@ -27,37 +27,39 @@ interface SvgOwnProps {
|
|
|
27
27
|
label?: string;
|
|
28
28
|
}
|
|
29
29
|
/** The `width`/`height` here are the SVG attributes, not the ÷4 layout props they are on a `<div>`. */
|
|
30
|
-
type Props = Omit<BoxProps<'svg'>, 'tag' | 'width' | 'height'> & SvgOwnProps;
|
|
30
|
+
type Props<TKey extends keyof ComponentsAndVariants = never> = Omit<BoxProps<'svg', TKey>, 'tag' | 'width' | 'height'> & SvgOwnProps;
|
|
31
31
|
/** The root `<svg>`: the coordinate system, the size, and whether a screen reader is told about it. */
|
|
32
|
-
export declare const Svg:
|
|
33
|
-
|
|
32
|
+
export declare const Svg: (<TKey extends keyof ComponentsAndVariants = never>(props: Props<TKey> & RefAttributes<SVGSVGElement>) => React.ReactNode) & {
|
|
33
|
+
displayName?: string;
|
|
34
|
+
};
|
|
35
|
+
export type SvgProps = Props & RefAttributes<SVGSVGElement>;
|
|
34
36
|
/**
|
|
35
37
|
* The rest of the elements, each with the attributes it owns — everything CSS styles on it stays a Box
|
|
36
38
|
* prop. `transform` is an attribute everywhere, because SVG's version carries its own centre of rotation
|
|
37
39
|
* (`rotate(-90 48 48)`) and the CSS `rotate` prop cannot say that without a `transformOrigin` we lack.
|
|
38
40
|
*/
|
|
39
|
-
export declare const G: SvgElementType<"g", "transform"
|
|
40
|
-
export declare const Defs: SvgElementType<"defs", keyof import('react').SVGProps<SVGDefsElement
|
|
41
|
-
export declare const Path: SvgElementType<"path", "transform" | "d" | "pathLength"
|
|
42
|
-
export declare const Circle: SvgElementType<"circle", "transform" | "pathLength"
|
|
43
|
-
export declare const Ellipse: SvgElementType<"ellipse", "transform" | "pathLength"
|
|
44
|
-
export declare const Rect: SvgElementType<"rect", "
|
|
45
|
-
export declare const Line: SvgElementType<"line", "transform" | "pathLength" | "x1" | "x2" | "y1" | "y2"
|
|
46
|
-
export declare const Polyline: SvgElementType<"polyline", "transform" | "pathLength" | "points"
|
|
47
|
-
export declare const Polygon: SvgElementType<"polygon", "transform" | "pathLength" | "points"
|
|
41
|
+
export declare const G: SvgElementType<"g", "transform">;
|
|
42
|
+
export declare const Defs: SvgElementType<"defs", keyof import('react').SVGProps<SVGDefsElement>>;
|
|
43
|
+
export declare const Path: SvgElementType<"path", "transform" | "d" | "pathLength">;
|
|
44
|
+
export declare const Circle: SvgElementType<"circle", "transform" | "pathLength">;
|
|
45
|
+
export declare const Ellipse: SvgElementType<"ellipse", "transform" | "pathLength">;
|
|
46
|
+
export declare const Rect: SvgElementType<"rect", "width" | "height" | "transform" | "pathLength">;
|
|
47
|
+
export declare const Line: SvgElementType<"line", "transform" | "pathLength" | "x1" | "x2" | "y1" | "y2">;
|
|
48
|
+
export declare const Polyline: SvgElementType<"polyline", "transform" | "pathLength" | "points">;
|
|
49
|
+
export declare const Polygon: SvgElementType<"polygon", "transform" | "pathLength" | "points">;
|
|
48
50
|
/**
|
|
49
51
|
* `SvgText`, not `Text`, which a future HTML text component would want. Its `x`/`y` are attributes: the
|
|
50
52
|
* CSS geometry properties do not apply to `<text>`, so the Box props of that name would move nothing.
|
|
51
53
|
*/
|
|
52
|
-
export declare const SvgText: SvgElementType<"text", "transform" | "x" | "y" | "dx" | "dy" | "lengthAdjust" | "textLength"
|
|
53
|
-
export declare const TSpan: SvgElementType<"tspan", "x" | "y" | "dx" | "dy" | "lengthAdjust" | "textLength"
|
|
54
|
-
export declare const LinearGradient: SvgElementType<"linearGradient", "gradientTransform" | "gradientUnits" | "spreadMethod" | "x1" | "x2" | "y1" | "y2"
|
|
55
|
-
export declare const RadialGradient: SvgElementType<"radialGradient", "cx" | "cy" | "r" | "fx" | "fy" | "gradientTransform" | "gradientUnits" | "spreadMethod"
|
|
56
|
-
export declare const Stop: SvgElementType<"stop", "stopColor" | "stopOpacity" | "offset"
|
|
57
|
-
export declare const ClipPath: SvgElementType<"clipPath", "transform" | "clipPathUnits"
|
|
58
|
-
export declare const Mask: SvgElementType<"mask", "
|
|
59
|
-
export declare const Use: SvgElementType<"use", "
|
|
54
|
+
export declare const SvgText: SvgElementType<"text", "transform" | "x" | "y" | "dx" | "dy" | "lengthAdjust" | "textLength">;
|
|
55
|
+
export declare const TSpan: SvgElementType<"tspan", "x" | "y" | "dx" | "dy" | "lengthAdjust" | "textLength">;
|
|
56
|
+
export declare const LinearGradient: SvgElementType<"linearGradient", "gradientTransform" | "gradientUnits" | "spreadMethod" | "x1" | "x2" | "y1" | "y2">;
|
|
57
|
+
export declare const RadialGradient: SvgElementType<"radialGradient", "cx" | "cy" | "r" | "fx" | "fy" | "gradientTransform" | "gradientUnits" | "spreadMethod">;
|
|
58
|
+
export declare const Stop: SvgElementType<"stop", "stopColor" | "stopOpacity" | "offset">;
|
|
59
|
+
export declare const ClipPath: SvgElementType<"clipPath", "transform" | "clipPathUnits">;
|
|
60
|
+
export declare const Mask: SvgElementType<"mask", "width" | "height" | "x" | "y" | "maskContentUnits" | "maskUnits">;
|
|
61
|
+
export declare const Use: SvgElementType<"use", "width" | "height" | "transform" | "href">;
|
|
60
62
|
/** `SvgSymbol`, not `Symbol` — the global of that name is not something a module should shadow. */
|
|
61
|
-
export declare const SvgSymbol: SvgElementType<"symbol", "
|
|
62
|
-
export declare const Marker: SvgElementType<"marker", "markerHeight" | "markerUnits" | "markerWidth" | "orient" | "refX" | "refY" | "viewBox"
|
|
63
|
+
export declare const SvgSymbol: SvgElementType<"symbol", "width" | "height" | "x" | "y" | "preserveAspectRatio" | "viewBox">;
|
|
64
|
+
export declare const Marker: SvgElementType<"marker", "markerHeight" | "markerUnits" | "markerWidth" | "orient" | "refX" | "refY" | "viewBox">;
|
|
63
65
|
export {};
|
package/components/svg.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as e,
|
|
1
|
+
import { a as e, c as t, o as n } from "../react-shared.mjs";
|
|
2
2
|
import { forwardRef as r } from "react";
|
|
3
3
|
import { jsx as i } from "react/jsx-runtime";
|
|
4
4
|
import a from "@box-kite/react";
|
|
@@ -25,7 +25,7 @@ function s(n, s = [], c) {
|
|
|
25
25
|
props: s
|
|
26
26
|
});
|
|
27
27
|
});
|
|
28
|
-
return u.displayName = c ??
|
|
28
|
+
return u.displayName = c ?? e.capitalize(n), t(u), u;
|
|
29
29
|
}
|
|
30
30
|
var c = "http://www.w3.org/2000/svg", l = [
|
|
31
31
|
"viewBox",
|
|
@@ -47,7 +47,7 @@ function u(e, t) {
|
|
|
47
47
|
}
|
|
48
48
|
});
|
|
49
49
|
}
|
|
50
|
-
var d = /* @__PURE__ */
|
|
50
|
+
var d = /* @__PURE__ */ t(r(u));
|
|
51
51
|
d.displayName = "Svg";
|
|
52
52
|
var f = /* @__PURE__ */ s("g", ["transform"]), p = /* @__PURE__ */ s("defs"), m = /* @__PURE__ */ s("path", [
|
|
53
53
|
"d",
|
package/components/switch.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});const e=require("../behavior.cjs"),t=require("./checkbox.cjs");let n=require("react"),r=require("react/jsx-runtime");function i(n,i){let{props:a,...o}=n,s=e.
|
|
1
|
+
"use client";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});const e=require("../behavior.cjs"),t=require("./checkbox.cjs");let n=require("react"),r=require("react/jsx-runtime");function i(n,i){let{props:a,...o}=n,s=e.a(a?.onKeyDown),c=e.a(e=>{s(e),!(e.key!==`Enter`||e.defaultPrevented)&&(e.preventDefault(),e.currentTarget.click())});return(0,r.jsx)(t.default,{ref:i,component:`switch`,...o,props:{...a,role:`switch`,onKeyDown:c}})}var a=(0,n.forwardRef)(i);a.displayName=`Switch`,exports.default=a;
|
package/components/switch.d.ts
CHANGED
|
@@ -4,16 +4,25 @@ import { OmitTagProps } from '../react/boxProps';
|
|
|
4
4
|
import { ComponentsAndVariants } from '@box-kite/core/types';
|
|
5
5
|
type SwitchProps<TKey extends keyof ComponentsAndVariants> = Omit<BoxProps<'input', TKey>, 'tag' | 'props' | 'indeterminate'>;
|
|
6
6
|
interface Props<TKey extends keyof ComponentsAndVariants> extends SwitchProps<TKey> {
|
|
7
|
+
/** What the switch submits under. Needed for a form; a controlled switch can do without one. */
|
|
7
8
|
name?: string;
|
|
9
|
+
/** Attributes for the `<input>` itself. `type` is the component's, and `role` is already `switch`. */
|
|
8
10
|
props?: OmitTagProps<BoxTagProps<'input'>, 'type'>;
|
|
11
|
+
/** Fires on every keystroke or click. On a checkbox this is the same moment as `onChange`. */
|
|
9
12
|
onInput?: (e: React.ChangeEvent<HTMLInputElement>) => void;
|
|
13
|
+
/** Fires when the switch is toggled. `e.target.checked` is the new state. */
|
|
10
14
|
onChange?: (e: React.ChangeEvent<HTMLInputElement>) => void;
|
|
15
|
+
/** The value the form submits when it is on. Defaults to `"on"`, as HTML does. */
|
|
11
16
|
value?: string | number;
|
|
17
|
+
/** Focus it on mount. One per page at most — a stolen focus is a lost place in the document. */
|
|
12
18
|
autoFocus?: boolean;
|
|
19
|
+
/** Rendered and read, but not toggleable. Unlike `disabled` it stays in the tab order and submits. */
|
|
13
20
|
readOnly?: boolean;
|
|
21
|
+
/** The state it starts in when the switch is uncontrolled. Pass `checked` instead to control it. */
|
|
14
22
|
defaultChecked?: boolean;
|
|
15
23
|
/** The text beside the switch, rendered inside a label that wraps the input. */
|
|
16
24
|
label?: React.ReactNode;
|
|
25
|
+
/** Styles for the wrapping `<label>`: the row's layout, not the track's own appearance. */
|
|
17
26
|
labelProps?: BoxProps<'label'>;
|
|
18
27
|
}
|
|
19
28
|
declare const _default: <TKey extends keyof ComponentsAndVariants = "switch">(props: Props<TKey> & RefAttributes<HTMLInputElement>) => React.ReactNode;
|
package/components/switch.mjs
CHANGED