@designa8/vibedesign-linear-internal-v1-b737 0.12.1 → 0.12.3
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/README.md +1 -1
- package/dist/index.cjs +122 -28
- package/dist/index.js +122 -28
- package/dist/styles.css +23 -0
- package/package.json +1 -1
- package/src/atoms/Drawer/Drawer.tsx +109 -10
- package/src/atoms/Drawer/preview.tsx +62 -0
- package/src/atoms/Switch/Switch.tsx +20 -3
- package/src/atoms/Switch/preview.tsx +65 -8
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @designa8/vibedesign-linear-internal-v1-b737
|
|
2
2
|
|
|
3
|
-
Complete design system generated by Atoms Design, version **0.12.
|
|
3
|
+
Complete design system generated by Atoms Design, version **0.12.3**.
|
|
4
4
|
Tokens, atoms, molecules, organisms, and templates — import from the package root;
|
|
5
5
|
never hardcode visual values in consumer code.
|
|
6
6
|
|
package/dist/index.cjs
CHANGED
|
@@ -5700,6 +5700,7 @@ var React46 = __toESM(require("react"));
|
|
|
5700
5700
|
var import_react_dom5 = require("react-dom");
|
|
5701
5701
|
var import_jsx_runtime46 = require("react/jsx-runtime");
|
|
5702
5702
|
var cn35 = (...parts) => parts.filter(Boolean).join(" ");
|
|
5703
|
+
var DISMISS_THRESHOLD = 0.3;
|
|
5703
5704
|
var Drawer = React46.forwardRef(
|
|
5704
5705
|
({
|
|
5705
5706
|
open,
|
|
@@ -5714,6 +5715,7 @@ var Drawer = React46.forwardRef(
|
|
|
5714
5715
|
"aria-label": ariaLabel,
|
|
5715
5716
|
closeOnScrimClick = true,
|
|
5716
5717
|
bodyClassName,
|
|
5718
|
+
showHandle = true,
|
|
5717
5719
|
className,
|
|
5718
5720
|
children,
|
|
5719
5721
|
...rest
|
|
@@ -5722,6 +5724,20 @@ var Drawer = React46.forwardRef(
|
|
|
5722
5724
|
const panelRef = React46.useRef(null);
|
|
5723
5725
|
const [mounted, setMounted] = React46.useState(false);
|
|
5724
5726
|
React46.useEffect(() => setMounted(true), []);
|
|
5727
|
+
const isBottom = side === "bottom";
|
|
5728
|
+
const [dragging, setDragging] = React46.useState(false);
|
|
5729
|
+
const [dragOffset, setDragOffset] = React46.useState(0);
|
|
5730
|
+
const dragStartY = React46.useRef(0);
|
|
5731
|
+
const dragHeight = React46.useRef(0);
|
|
5732
|
+
const endDrag = React46.useCallback(
|
|
5733
|
+
(close) => {
|
|
5734
|
+
const passed = dragOffset > (dragHeight.current || 0) * DISMISS_THRESHOLD;
|
|
5735
|
+
setDragging(false);
|
|
5736
|
+
setDragOffset(0);
|
|
5737
|
+
if (close && passed) onOpenChange(false);
|
|
5738
|
+
},
|
|
5739
|
+
[dragOffset, onOpenChange]
|
|
5740
|
+
);
|
|
5725
5741
|
React46.useEffect(() => {
|
|
5726
5742
|
if (!open) return;
|
|
5727
5743
|
const onKey = (e) => {
|
|
@@ -5748,13 +5764,40 @@ var Drawer = React46.forwardRef(
|
|
|
5748
5764
|
window.clearTimeout(t);
|
|
5749
5765
|
};
|
|
5750
5766
|
}, [open, onOpenChange, closeOnScrimClick]);
|
|
5767
|
+
const onHandlePointerDown = (e) => {
|
|
5768
|
+
if (!isBottom) return;
|
|
5769
|
+
dragStartY.current = e.clientY;
|
|
5770
|
+
dragHeight.current = panelRef.current?.getBoundingClientRect().height ?? 0;
|
|
5771
|
+
setDragging(true);
|
|
5772
|
+
setDragOffset(0);
|
|
5773
|
+
e.currentTarget.setPointerCapture?.(e.pointerId);
|
|
5774
|
+
};
|
|
5775
|
+
const onHandlePointerMove = (e) => {
|
|
5776
|
+
if (!dragging) return;
|
|
5777
|
+
const next = Math.max(0, e.clientY - dragStartY.current);
|
|
5778
|
+
setDragOffset(Math.min(next, dragHeight.current || next));
|
|
5779
|
+
};
|
|
5780
|
+
const onHandlePointerUp = (e) => {
|
|
5781
|
+
if (!dragging) return;
|
|
5782
|
+
try {
|
|
5783
|
+
e.currentTarget.releasePointerCapture?.(e.pointerId);
|
|
5784
|
+
} catch {
|
|
5785
|
+
}
|
|
5786
|
+
endDrag(true);
|
|
5787
|
+
};
|
|
5788
|
+
const onHandlePointerCancel = () => {
|
|
5789
|
+
if (!dragging) return;
|
|
5790
|
+
endDrag(false);
|
|
5791
|
+
};
|
|
5751
5792
|
const state = open ? "open" : "closed";
|
|
5752
5793
|
const hasTitle = title !== void 0 && title !== null;
|
|
5794
|
+
const sideClasses = isBottom ? "inset-x-0 bottom-0 w-full rounded-t-xl border-t border-hairline shadow-card data-[state=open]:translate-y-0 data-[state=closed]:translate-y-full" : side === "right" ? "inset-y-0 right-0 w-full border-l border-hairline shadow-modal sm:w-[var(--container-drawer,448px)] data-[state=open]:translate-x-0 data-[state=closed]:translate-x-full" : "inset-y-0 left-0 w-full border-r border-hairline shadow-modal sm:w-[var(--container-drawer,448px)] data-[state=open]:translate-x-0 data-[state=closed]:-translate-x-full";
|
|
5795
|
+
const scrimDragOpacity = dragging ? Math.max(0, 1 - dragOffset / Math.max(dragHeight.current, 1)) : void 0;
|
|
5753
5796
|
const node = /* @__PURE__ */ (0, import_jsx_runtime46.jsxs)(
|
|
5754
5797
|
"div",
|
|
5755
5798
|
{
|
|
5756
5799
|
"data-state": state,
|
|
5757
|
-
className: "fixed inset-0 data-[state=closed]:pointer-events-none",
|
|
5800
|
+
className: "fixed inset-0 overflow-hidden data-[state=closed]:pointer-events-none",
|
|
5758
5801
|
style: { zIndex: "var(--z-modal, 1200)" },
|
|
5759
5802
|
"aria-hidden": open ? void 0 : true,
|
|
5760
5803
|
children: [
|
|
@@ -5763,7 +5806,11 @@ var Drawer = React46.forwardRef(
|
|
|
5763
5806
|
{
|
|
5764
5807
|
"data-state": state,
|
|
5765
5808
|
"aria-hidden": "true",
|
|
5766
|
-
className:
|
|
5809
|
+
className: cn35(
|
|
5810
|
+
dragging ? "transition-none" : "transition-opacity duration-200 ease-out",
|
|
5811
|
+
"fixed inset-0 bg-scrim/40 data-[state=open]:opacity-100 data-[state=closed]:opacity-0"
|
|
5812
|
+
),
|
|
5813
|
+
style: scrimDragOpacity === void 0 ? void 0 : { opacity: scrimDragOpacity }
|
|
5767
5814
|
}
|
|
5768
5815
|
),
|
|
5769
5816
|
/* @__PURE__ */ (0, import_jsx_runtime46.jsxs)(
|
|
@@ -5782,29 +5829,55 @@ var Drawer = React46.forwardRef(
|
|
|
5782
5829
|
"data-side": side,
|
|
5783
5830
|
"data-drawer": "",
|
|
5784
5831
|
className: cn35(
|
|
5785
|
-
"fixed
|
|
5786
|
-
|
|
5787
|
-
"data-[state=open]:translate-x-0 data-[state=closed]:invisible",
|
|
5832
|
+
"fixed flex flex-col overflow-hidden bg-canvas text-ink transition ease-out data-[state=closed]:invisible",
|
|
5833
|
+
sideClasses,
|
|
5788
5834
|
className
|
|
5789
5835
|
),
|
|
5836
|
+
style: {
|
|
5837
|
+
maxHeight: isBottom ? "90dvh" : void 0,
|
|
5838
|
+
paddingBottom: isBottom ? "env(safe-area-inset-bottom, 0px)" : void 0,
|
|
5839
|
+
transform: isBottom && dragging && dragOffset > 0 ? `translateY(${dragOffset}px)` : void 0,
|
|
5840
|
+
transitionDuration: dragging ? "0ms" : "240ms"
|
|
5841
|
+
},
|
|
5790
5842
|
...rest,
|
|
5791
5843
|
children: [
|
|
5792
|
-
|
|
5793
|
-
|
|
5794
|
-
|
|
5795
|
-
|
|
5796
|
-
|
|
5797
|
-
|
|
5798
|
-
|
|
5799
|
-
|
|
5800
|
-
|
|
5801
|
-
|
|
5802
|
-
|
|
5803
|
-
|
|
5804
|
-
|
|
5805
|
-
|
|
5806
|
-
|
|
5807
|
-
|
|
5844
|
+
isBottom && showHandle && /* @__PURE__ */ (0, import_jsx_runtime46.jsx)(
|
|
5845
|
+
"div",
|
|
5846
|
+
{
|
|
5847
|
+
"aria-hidden": "true",
|
|
5848
|
+
onPointerDown: onHandlePointerDown,
|
|
5849
|
+
onPointerMove: onHandlePointerMove,
|
|
5850
|
+
onPointerUp: onHandlePointerUp,
|
|
5851
|
+
onPointerCancel: onHandlePointerCancel,
|
|
5852
|
+
className: "flex shrink-0 cursor-grab touch-none select-none items-center justify-center pb-xs pt-sm active:cursor-grabbing",
|
|
5853
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime46.jsx)("span", { className: "h-1 w-10 rounded-full bg-hairline-strong" })
|
|
5854
|
+
}
|
|
5855
|
+
),
|
|
5856
|
+
!hideHeader && /* @__PURE__ */ (0, import_jsx_runtime46.jsxs)(
|
|
5857
|
+
"div",
|
|
5858
|
+
{
|
|
5859
|
+
className: cn35(
|
|
5860
|
+
"flex shrink-0 items-center justify-between gap-sm px-base pb-sm",
|
|
5861
|
+
isBottom ? "pt-xs" : "pt-base"
|
|
5862
|
+
),
|
|
5863
|
+
children: [
|
|
5864
|
+
/* @__PURE__ */ (0, import_jsx_runtime46.jsxs)("div", { className: "flex min-w-0 flex-1 items-center gap-sm", children: [
|
|
5865
|
+
headerStart,
|
|
5866
|
+
hasTitle && /* @__PURE__ */ (0, import_jsx_runtime46.jsx)("h2", { id: titleId, className: "truncate text-heading-sm text-ink", children: title })
|
|
5867
|
+
] }),
|
|
5868
|
+
/* @__PURE__ */ (0, import_jsx_runtime46.jsx)(
|
|
5869
|
+
IconButton,
|
|
5870
|
+
{
|
|
5871
|
+
icon: closeIcon,
|
|
5872
|
+
variant: closeIcon === "x" ? "ghost" : "secondary",
|
|
5873
|
+
size: "md",
|
|
5874
|
+
"aria-label": closeLabel,
|
|
5875
|
+
onClick: () => onOpenChange(false)
|
|
5876
|
+
}
|
|
5877
|
+
)
|
|
5878
|
+
]
|
|
5879
|
+
}
|
|
5880
|
+
),
|
|
5808
5881
|
/* @__PURE__ */ (0, import_jsx_runtime46.jsx)(
|
|
5809
5882
|
"div",
|
|
5810
5883
|
{
|
|
@@ -9165,6 +9238,7 @@ var Switch = React73.forwardRef(
|
|
|
9165
9238
|
onChange?.(e);
|
|
9166
9239
|
};
|
|
9167
9240
|
const labelled = Boolean(label);
|
|
9241
|
+
const hasDescription = Boolean(description);
|
|
9168
9242
|
return /* @__PURE__ */ (0, import_jsx_runtime73.jsxs)(
|
|
9169
9243
|
"label",
|
|
9170
9244
|
{
|
|
@@ -9176,13 +9250,33 @@ var Switch = React73.forwardRef(
|
|
|
9176
9250
|
className
|
|
9177
9251
|
].filter(Boolean).join(" "),
|
|
9178
9252
|
children: [
|
|
9179
|
-
labelled ? /* @__PURE__ */ (0, import_jsx_runtime73.jsxs)(
|
|
9180
|
-
|
|
9181
|
-
|
|
9182
|
-
|
|
9183
|
-
|
|
9184
|
-
|
|
9185
|
-
|
|
9253
|
+
labelled ? /* @__PURE__ */ (0, import_jsx_runtime73.jsxs)(
|
|
9254
|
+
"span",
|
|
9255
|
+
{
|
|
9256
|
+
className: [
|
|
9257
|
+
"flex min-w-0 gap-md",
|
|
9258
|
+
/* With a description the leading visual aligns to the first line;
|
|
9259
|
+
with a single-line label it centers with that line. */
|
|
9260
|
+
hasDescription ? "items-start" : "items-center"
|
|
9261
|
+
].join(" "),
|
|
9262
|
+
children: [
|
|
9263
|
+
leading ? /* @__PURE__ */ (0, import_jsx_runtime73.jsx)(
|
|
9264
|
+
"span",
|
|
9265
|
+
{
|
|
9266
|
+
className: [
|
|
9267
|
+
"inline-flex shrink-0 text-ink",
|
|
9268
|
+
hasDescription ? "mt-xxs" : ""
|
|
9269
|
+
].filter(Boolean).join(" "),
|
|
9270
|
+
children: leading
|
|
9271
|
+
}
|
|
9272
|
+
) : null,
|
|
9273
|
+
/* @__PURE__ */ (0, import_jsx_runtime73.jsxs)("span", { className: "flex min-w-0 flex-col", children: [
|
|
9274
|
+
/* @__PURE__ */ (0, import_jsx_runtime73.jsx)("span", { className: "text-body-md text-ink", children: label }),
|
|
9275
|
+
hasDescription ? /* @__PURE__ */ (0, import_jsx_runtime73.jsx)("span", { id: descId, className: "text-body-sm text-muted", children: description }) : null
|
|
9276
|
+
] })
|
|
9277
|
+
]
|
|
9278
|
+
}
|
|
9279
|
+
) : null,
|
|
9186
9280
|
/* @__PURE__ */ (0, import_jsx_runtime73.jsxs)("span", { className: "relative inline-flex shrink-0 items-center", children: [
|
|
9187
9281
|
/* @__PURE__ */ (0, import_jsx_runtime73.jsx)(
|
|
9188
9282
|
"input",
|
package/dist/index.js
CHANGED
|
@@ -5555,6 +5555,7 @@ import * as React46 from "react";
|
|
|
5555
5555
|
import { createPortal as createPortal5 } from "react-dom";
|
|
5556
5556
|
import { jsx as jsx46, jsxs as jsxs40 } from "react/jsx-runtime";
|
|
5557
5557
|
var cn35 = (...parts) => parts.filter(Boolean).join(" ");
|
|
5558
|
+
var DISMISS_THRESHOLD = 0.3;
|
|
5558
5559
|
var Drawer = React46.forwardRef(
|
|
5559
5560
|
({
|
|
5560
5561
|
open,
|
|
@@ -5569,6 +5570,7 @@ var Drawer = React46.forwardRef(
|
|
|
5569
5570
|
"aria-label": ariaLabel,
|
|
5570
5571
|
closeOnScrimClick = true,
|
|
5571
5572
|
bodyClassName,
|
|
5573
|
+
showHandle = true,
|
|
5572
5574
|
className,
|
|
5573
5575
|
children,
|
|
5574
5576
|
...rest
|
|
@@ -5577,6 +5579,20 @@ var Drawer = React46.forwardRef(
|
|
|
5577
5579
|
const panelRef = React46.useRef(null);
|
|
5578
5580
|
const [mounted, setMounted] = React46.useState(false);
|
|
5579
5581
|
React46.useEffect(() => setMounted(true), []);
|
|
5582
|
+
const isBottom = side === "bottom";
|
|
5583
|
+
const [dragging, setDragging] = React46.useState(false);
|
|
5584
|
+
const [dragOffset, setDragOffset] = React46.useState(0);
|
|
5585
|
+
const dragStartY = React46.useRef(0);
|
|
5586
|
+
const dragHeight = React46.useRef(0);
|
|
5587
|
+
const endDrag = React46.useCallback(
|
|
5588
|
+
(close) => {
|
|
5589
|
+
const passed = dragOffset > (dragHeight.current || 0) * DISMISS_THRESHOLD;
|
|
5590
|
+
setDragging(false);
|
|
5591
|
+
setDragOffset(0);
|
|
5592
|
+
if (close && passed) onOpenChange(false);
|
|
5593
|
+
},
|
|
5594
|
+
[dragOffset, onOpenChange]
|
|
5595
|
+
);
|
|
5580
5596
|
React46.useEffect(() => {
|
|
5581
5597
|
if (!open) return;
|
|
5582
5598
|
const onKey = (e) => {
|
|
@@ -5603,13 +5619,40 @@ var Drawer = React46.forwardRef(
|
|
|
5603
5619
|
window.clearTimeout(t);
|
|
5604
5620
|
};
|
|
5605
5621
|
}, [open, onOpenChange, closeOnScrimClick]);
|
|
5622
|
+
const onHandlePointerDown = (e) => {
|
|
5623
|
+
if (!isBottom) return;
|
|
5624
|
+
dragStartY.current = e.clientY;
|
|
5625
|
+
dragHeight.current = panelRef.current?.getBoundingClientRect().height ?? 0;
|
|
5626
|
+
setDragging(true);
|
|
5627
|
+
setDragOffset(0);
|
|
5628
|
+
e.currentTarget.setPointerCapture?.(e.pointerId);
|
|
5629
|
+
};
|
|
5630
|
+
const onHandlePointerMove = (e) => {
|
|
5631
|
+
if (!dragging) return;
|
|
5632
|
+
const next = Math.max(0, e.clientY - dragStartY.current);
|
|
5633
|
+
setDragOffset(Math.min(next, dragHeight.current || next));
|
|
5634
|
+
};
|
|
5635
|
+
const onHandlePointerUp = (e) => {
|
|
5636
|
+
if (!dragging) return;
|
|
5637
|
+
try {
|
|
5638
|
+
e.currentTarget.releasePointerCapture?.(e.pointerId);
|
|
5639
|
+
} catch {
|
|
5640
|
+
}
|
|
5641
|
+
endDrag(true);
|
|
5642
|
+
};
|
|
5643
|
+
const onHandlePointerCancel = () => {
|
|
5644
|
+
if (!dragging) return;
|
|
5645
|
+
endDrag(false);
|
|
5646
|
+
};
|
|
5606
5647
|
const state = open ? "open" : "closed";
|
|
5607
5648
|
const hasTitle = title !== void 0 && title !== null;
|
|
5649
|
+
const sideClasses = isBottom ? "inset-x-0 bottom-0 w-full rounded-t-xl border-t border-hairline shadow-card data-[state=open]:translate-y-0 data-[state=closed]:translate-y-full" : side === "right" ? "inset-y-0 right-0 w-full border-l border-hairline shadow-modal sm:w-[var(--container-drawer,448px)] data-[state=open]:translate-x-0 data-[state=closed]:translate-x-full" : "inset-y-0 left-0 w-full border-r border-hairline shadow-modal sm:w-[var(--container-drawer,448px)] data-[state=open]:translate-x-0 data-[state=closed]:-translate-x-full";
|
|
5650
|
+
const scrimDragOpacity = dragging ? Math.max(0, 1 - dragOffset / Math.max(dragHeight.current, 1)) : void 0;
|
|
5608
5651
|
const node = /* @__PURE__ */ jsxs40(
|
|
5609
5652
|
"div",
|
|
5610
5653
|
{
|
|
5611
5654
|
"data-state": state,
|
|
5612
|
-
className: "fixed inset-0 data-[state=closed]:pointer-events-none",
|
|
5655
|
+
className: "fixed inset-0 overflow-hidden data-[state=closed]:pointer-events-none",
|
|
5613
5656
|
style: { zIndex: "var(--z-modal, 1200)" },
|
|
5614
5657
|
"aria-hidden": open ? void 0 : true,
|
|
5615
5658
|
children: [
|
|
@@ -5618,7 +5661,11 @@ var Drawer = React46.forwardRef(
|
|
|
5618
5661
|
{
|
|
5619
5662
|
"data-state": state,
|
|
5620
5663
|
"aria-hidden": "true",
|
|
5621
|
-
className:
|
|
5664
|
+
className: cn35(
|
|
5665
|
+
dragging ? "transition-none" : "transition-opacity duration-200 ease-out",
|
|
5666
|
+
"fixed inset-0 bg-scrim/40 data-[state=open]:opacity-100 data-[state=closed]:opacity-0"
|
|
5667
|
+
),
|
|
5668
|
+
style: scrimDragOpacity === void 0 ? void 0 : { opacity: scrimDragOpacity }
|
|
5622
5669
|
}
|
|
5623
5670
|
),
|
|
5624
5671
|
/* @__PURE__ */ jsxs40(
|
|
@@ -5637,29 +5684,55 @@ var Drawer = React46.forwardRef(
|
|
|
5637
5684
|
"data-side": side,
|
|
5638
5685
|
"data-drawer": "",
|
|
5639
5686
|
className: cn35(
|
|
5640
|
-
"fixed
|
|
5641
|
-
|
|
5642
|
-
"data-[state=open]:translate-x-0 data-[state=closed]:invisible",
|
|
5687
|
+
"fixed flex flex-col overflow-hidden bg-canvas text-ink transition ease-out data-[state=closed]:invisible",
|
|
5688
|
+
sideClasses,
|
|
5643
5689
|
className
|
|
5644
5690
|
),
|
|
5691
|
+
style: {
|
|
5692
|
+
maxHeight: isBottom ? "90dvh" : void 0,
|
|
5693
|
+
paddingBottom: isBottom ? "env(safe-area-inset-bottom, 0px)" : void 0,
|
|
5694
|
+
transform: isBottom && dragging && dragOffset > 0 ? `translateY(${dragOffset}px)` : void 0,
|
|
5695
|
+
transitionDuration: dragging ? "0ms" : "240ms"
|
|
5696
|
+
},
|
|
5645
5697
|
...rest,
|
|
5646
5698
|
children: [
|
|
5647
|
-
|
|
5648
|
-
|
|
5649
|
-
|
|
5650
|
-
|
|
5651
|
-
|
|
5652
|
-
|
|
5653
|
-
|
|
5654
|
-
|
|
5655
|
-
|
|
5656
|
-
|
|
5657
|
-
|
|
5658
|
-
|
|
5659
|
-
|
|
5660
|
-
|
|
5661
|
-
|
|
5662
|
-
|
|
5699
|
+
isBottom && showHandle && /* @__PURE__ */ jsx46(
|
|
5700
|
+
"div",
|
|
5701
|
+
{
|
|
5702
|
+
"aria-hidden": "true",
|
|
5703
|
+
onPointerDown: onHandlePointerDown,
|
|
5704
|
+
onPointerMove: onHandlePointerMove,
|
|
5705
|
+
onPointerUp: onHandlePointerUp,
|
|
5706
|
+
onPointerCancel: onHandlePointerCancel,
|
|
5707
|
+
className: "flex shrink-0 cursor-grab touch-none select-none items-center justify-center pb-xs pt-sm active:cursor-grabbing",
|
|
5708
|
+
children: /* @__PURE__ */ jsx46("span", { className: "h-1 w-10 rounded-full bg-hairline-strong" })
|
|
5709
|
+
}
|
|
5710
|
+
),
|
|
5711
|
+
!hideHeader && /* @__PURE__ */ jsxs40(
|
|
5712
|
+
"div",
|
|
5713
|
+
{
|
|
5714
|
+
className: cn35(
|
|
5715
|
+
"flex shrink-0 items-center justify-between gap-sm px-base pb-sm",
|
|
5716
|
+
isBottom ? "pt-xs" : "pt-base"
|
|
5717
|
+
),
|
|
5718
|
+
children: [
|
|
5719
|
+
/* @__PURE__ */ jsxs40("div", { className: "flex min-w-0 flex-1 items-center gap-sm", children: [
|
|
5720
|
+
headerStart,
|
|
5721
|
+
hasTitle && /* @__PURE__ */ jsx46("h2", { id: titleId, className: "truncate text-heading-sm text-ink", children: title })
|
|
5722
|
+
] }),
|
|
5723
|
+
/* @__PURE__ */ jsx46(
|
|
5724
|
+
IconButton,
|
|
5725
|
+
{
|
|
5726
|
+
icon: closeIcon,
|
|
5727
|
+
variant: closeIcon === "x" ? "ghost" : "secondary",
|
|
5728
|
+
size: "md",
|
|
5729
|
+
"aria-label": closeLabel,
|
|
5730
|
+
onClick: () => onOpenChange(false)
|
|
5731
|
+
}
|
|
5732
|
+
)
|
|
5733
|
+
]
|
|
5734
|
+
}
|
|
5735
|
+
),
|
|
5663
5736
|
/* @__PURE__ */ jsx46(
|
|
5664
5737
|
"div",
|
|
5665
5738
|
{
|
|
@@ -9020,6 +9093,7 @@ var Switch = React73.forwardRef(
|
|
|
9020
9093
|
onChange?.(e);
|
|
9021
9094
|
};
|
|
9022
9095
|
const labelled = Boolean(label);
|
|
9096
|
+
const hasDescription = Boolean(description);
|
|
9023
9097
|
return /* @__PURE__ */ jsxs67(
|
|
9024
9098
|
"label",
|
|
9025
9099
|
{
|
|
@@ -9031,13 +9105,33 @@ var Switch = React73.forwardRef(
|
|
|
9031
9105
|
className
|
|
9032
9106
|
].filter(Boolean).join(" "),
|
|
9033
9107
|
children: [
|
|
9034
|
-
labelled ? /* @__PURE__ */ jsxs67(
|
|
9035
|
-
|
|
9036
|
-
|
|
9037
|
-
|
|
9038
|
-
|
|
9039
|
-
|
|
9040
|
-
|
|
9108
|
+
labelled ? /* @__PURE__ */ jsxs67(
|
|
9109
|
+
"span",
|
|
9110
|
+
{
|
|
9111
|
+
className: [
|
|
9112
|
+
"flex min-w-0 gap-md",
|
|
9113
|
+
/* With a description the leading visual aligns to the first line;
|
|
9114
|
+
with a single-line label it centers with that line. */
|
|
9115
|
+
hasDescription ? "items-start" : "items-center"
|
|
9116
|
+
].join(" "),
|
|
9117
|
+
children: [
|
|
9118
|
+
leading ? /* @__PURE__ */ jsx73(
|
|
9119
|
+
"span",
|
|
9120
|
+
{
|
|
9121
|
+
className: [
|
|
9122
|
+
"inline-flex shrink-0 text-ink",
|
|
9123
|
+
hasDescription ? "mt-xxs" : ""
|
|
9124
|
+
].filter(Boolean).join(" "),
|
|
9125
|
+
children: leading
|
|
9126
|
+
}
|
|
9127
|
+
) : null,
|
|
9128
|
+
/* @__PURE__ */ jsxs67("span", { className: "flex min-w-0 flex-col", children: [
|
|
9129
|
+
/* @__PURE__ */ jsx73("span", { className: "text-body-md text-ink", children: label }),
|
|
9130
|
+
hasDescription ? /* @__PURE__ */ jsx73("span", { id: descId, className: "text-body-sm text-muted", children: description }) : null
|
|
9131
|
+
] })
|
|
9132
|
+
]
|
|
9133
|
+
}
|
|
9134
|
+
) : null,
|
|
9041
9135
|
/* @__PURE__ */ jsxs67("span", { className: "relative inline-flex shrink-0 items-center", children: [
|
|
9042
9136
|
/* @__PURE__ */ jsx73(
|
|
9043
9137
|
"input",
|
package/dist/styles.css
CHANGED
|
@@ -18,6 +18,7 @@
|
|
|
18
18
|
--container-3xl: 48rem;
|
|
19
19
|
--container-4xl: 56rem;
|
|
20
20
|
--container-5xl: 64rem;
|
|
21
|
+
--tracking-wide: 0.025em;
|
|
21
22
|
--radius-xs: 4px;
|
|
22
23
|
--radius-sm: 6px;
|
|
23
24
|
--radius-md: 8px;
|
|
@@ -1062,6 +1063,9 @@
|
|
|
1062
1063
|
.cursor-default {
|
|
1063
1064
|
cursor: default;
|
|
1064
1065
|
}
|
|
1066
|
+
.cursor-grab {
|
|
1067
|
+
cursor: grab;
|
|
1068
|
+
}
|
|
1065
1069
|
.cursor-not-allowed {
|
|
1066
1070
|
cursor: not-allowed;
|
|
1067
1071
|
}
|
|
@@ -1321,6 +1325,10 @@
|
|
|
1321
1325
|
border-top-left-radius: var(--radius-lg);
|
|
1322
1326
|
border-top-right-radius: var(--radius-lg);
|
|
1323
1327
|
}
|
|
1328
|
+
.rounded-t-xl {
|
|
1329
|
+
border-top-left-radius: var(--radius-xl);
|
|
1330
|
+
border-top-right-radius: var(--radius-xl);
|
|
1331
|
+
}
|
|
1324
1332
|
.rounded-t-xs {
|
|
1325
1333
|
border-top-left-radius: var(--radius-xs);
|
|
1326
1334
|
border-top-right-radius: var(--radius-xs);
|
|
@@ -1657,6 +1665,9 @@
|
|
|
1657
1665
|
.py-xxs {
|
|
1658
1666
|
padding-block: var(--spacing-xxs);
|
|
1659
1667
|
}
|
|
1668
|
+
.pt-0 {
|
|
1669
|
+
padding-top: 0;
|
|
1670
|
+
}
|
|
1660
1671
|
.pt-base {
|
|
1661
1672
|
padding-top: var(--spacing-base);
|
|
1662
1673
|
}
|
|
@@ -1828,6 +1839,10 @@
|
|
|
1828
1839
|
--tw-tracking: var(--tracking-overline);
|
|
1829
1840
|
letter-spacing: var(--tracking-overline);
|
|
1830
1841
|
}
|
|
1842
|
+
.tracking-wide {
|
|
1843
|
+
--tw-tracking: var(--tracking-wide);
|
|
1844
|
+
letter-spacing: var(--tracking-wide);
|
|
1845
|
+
}
|
|
1831
1846
|
.break-words {
|
|
1832
1847
|
overflow-wrap: break-word;
|
|
1833
1848
|
}
|
|
@@ -2024,6 +2039,9 @@
|
|
|
2024
2039
|
transition-timing-function: var(--tw-ease, var(--default-transition-timing-function));
|
|
2025
2040
|
transition-duration: var(--tw-duration, var(--default-transition-duration));
|
|
2026
2041
|
}
|
|
2042
|
+
.transition-none {
|
|
2043
|
+
transition-property: none;
|
|
2044
|
+
}
|
|
2027
2045
|
.duration-150 {
|
|
2028
2046
|
--tw-duration: 150ms;
|
|
2029
2047
|
transition-duration: 150ms;
|
|
@@ -2476,6 +2494,11 @@
|
|
|
2476
2494
|
}
|
|
2477
2495
|
}
|
|
2478
2496
|
}
|
|
2497
|
+
.active\:cursor-grabbing {
|
|
2498
|
+
&:active {
|
|
2499
|
+
cursor: grabbing;
|
|
2500
|
+
}
|
|
2501
|
+
}
|
|
2479
2502
|
.active\:bg-surface-strong {
|
|
2480
2503
|
&:active {
|
|
2481
2504
|
background-color: var(--color-surface-strong);
|
package/package.json
CHANGED
|
@@ -3,14 +3,17 @@ import { createPortal } from "react-dom";
|
|
|
3
3
|
import { IconButton } from "../IconButton";
|
|
4
4
|
import type { IconName } from "../Icon";
|
|
5
5
|
|
|
6
|
-
export type DrawerSide = "left" | "right";
|
|
6
|
+
export type DrawerSide = "left" | "right" | "bottom";
|
|
7
7
|
|
|
8
8
|
export interface DrawerProps
|
|
9
9
|
extends Omit<React.HTMLAttributes<HTMLDivElement>, "title"> {
|
|
10
10
|
/** Controlled open state. */
|
|
11
11
|
open: boolean;
|
|
12
12
|
onOpenChange: (open: boolean) => void;
|
|
13
|
-
/**
|
|
13
|
+
/**
|
|
14
|
+
* Edge the panel is pinned to and slides in from. `"bottom"` renders a
|
|
15
|
+
* content-sized sheet pinned to the bottom edge (mobile action sheet).
|
|
16
|
+
*/
|
|
14
17
|
side?: DrawerSide;
|
|
15
18
|
/** Title shown in the default header row; also the dialog's accessible name. */
|
|
16
19
|
title?: React.ReactNode;
|
|
@@ -29,11 +32,19 @@ export interface DrawerProps
|
|
|
29
32
|
closeOnScrimClick?: boolean;
|
|
30
33
|
/** Class for the scrolling body. */
|
|
31
34
|
bodyClassName?: string;
|
|
35
|
+
/**
|
|
36
|
+
* Show the drag handle above the header. Defaults to true for
|
|
37
|
+
* `side="bottom"`; ignored for `left` / `right`.
|
|
38
|
+
*/
|
|
39
|
+
showHandle?: boolean;
|
|
32
40
|
}
|
|
33
41
|
|
|
34
42
|
const cn = (...parts: Array<string | false | null | undefined>) =>
|
|
35
43
|
parts.filter(Boolean).join(" ");
|
|
36
44
|
|
|
45
|
+
/** Fraction of the sheet height a downward drag must pass to dismiss. */
|
|
46
|
+
const DISMISS_THRESHOLD = 0.3;
|
|
47
|
+
|
|
37
48
|
export const Drawer = React.forwardRef<HTMLDivElement, DrawerProps>(
|
|
38
49
|
(
|
|
39
50
|
{
|
|
@@ -49,6 +60,7 @@ export const Drawer = React.forwardRef<HTMLDivElement, DrawerProps>(
|
|
|
49
60
|
"aria-label": ariaLabel,
|
|
50
61
|
closeOnScrimClick = true,
|
|
51
62
|
bodyClassName,
|
|
63
|
+
showHandle = true,
|
|
52
64
|
className,
|
|
53
65
|
children,
|
|
54
66
|
...rest
|
|
@@ -60,6 +72,25 @@ export const Drawer = React.forwardRef<HTMLDivElement, DrawerProps>(
|
|
|
60
72
|
const [mounted, setMounted] = React.useState(false);
|
|
61
73
|
React.useEffect(() => setMounted(true), []);
|
|
62
74
|
|
|
75
|
+
const isBottom = side === "bottom";
|
|
76
|
+
|
|
77
|
+
/** Drag-to-dismiss state (bottom sheet only). */
|
|
78
|
+
const [dragging, setDragging] = React.useState(false);
|
|
79
|
+
const [dragOffset, setDragOffset] = React.useState(0);
|
|
80
|
+
const dragStartY = React.useRef(0);
|
|
81
|
+
const dragHeight = React.useRef(0);
|
|
82
|
+
|
|
83
|
+
const endDrag = React.useCallback(
|
|
84
|
+
(close: boolean) => {
|
|
85
|
+
const passed =
|
|
86
|
+
dragOffset > (dragHeight.current || 0) * DISMISS_THRESHOLD;
|
|
87
|
+
setDragging(false);
|
|
88
|
+
setDragOffset(0);
|
|
89
|
+
if (close && passed) onOpenChange(false);
|
|
90
|
+
},
|
|
91
|
+
[dragOffset, onOpenChange],
|
|
92
|
+
);
|
|
93
|
+
|
|
63
94
|
React.useEffect(() => {
|
|
64
95
|
if (!open) return;
|
|
65
96
|
const onKey = (e: KeyboardEvent) => {
|
|
@@ -88,20 +119,65 @@ export const Drawer = React.forwardRef<HTMLDivElement, DrawerProps>(
|
|
|
88
119
|
};
|
|
89
120
|
}, [open, onOpenChange, closeOnScrimClick]);
|
|
90
121
|
|
|
122
|
+
const onHandlePointerDown = (e: React.PointerEvent<HTMLDivElement>) => {
|
|
123
|
+
if (!isBottom) return;
|
|
124
|
+
dragStartY.current = e.clientY;
|
|
125
|
+
dragHeight.current = panelRef.current?.getBoundingClientRect().height ?? 0;
|
|
126
|
+
setDragging(true);
|
|
127
|
+
setDragOffset(0);
|
|
128
|
+
e.currentTarget.setPointerCapture?.(e.pointerId);
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
const onHandlePointerMove = (e: React.PointerEvent<HTMLDivElement>) => {
|
|
132
|
+
if (!dragging) return;
|
|
133
|
+
const next = Math.max(0, e.clientY - dragStartY.current);
|
|
134
|
+
setDragOffset(Math.min(next, dragHeight.current || next));
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
const onHandlePointerUp = (e: React.PointerEvent<HTMLDivElement>) => {
|
|
138
|
+
if (!dragging) return;
|
|
139
|
+
try {
|
|
140
|
+
e.currentTarget.releasePointerCapture?.(e.pointerId);
|
|
141
|
+
} catch {
|
|
142
|
+
/* pointer already released */
|
|
143
|
+
}
|
|
144
|
+
endDrag(true);
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
const onHandlePointerCancel = () => {
|
|
148
|
+
if (!dragging) return;
|
|
149
|
+
endDrag(false);
|
|
150
|
+
};
|
|
151
|
+
|
|
91
152
|
const state = open ? "open" : "closed";
|
|
92
153
|
const hasTitle = title !== undefined && title !== null;
|
|
93
154
|
|
|
155
|
+
const sideClasses = isBottom
|
|
156
|
+
? "inset-x-0 bottom-0 w-full rounded-t-xl border-t border-hairline shadow-card data-[state=open]:translate-y-0 data-[state=closed]:translate-y-full"
|
|
157
|
+
: side === "right"
|
|
158
|
+
? "inset-y-0 right-0 w-full border-l border-hairline shadow-modal sm:w-[var(--container-drawer,448px)] data-[state=open]:translate-x-0 data-[state=closed]:translate-x-full"
|
|
159
|
+
: "inset-y-0 left-0 w-full border-r border-hairline shadow-modal sm:w-[var(--container-drawer,448px)] data-[state=open]:translate-x-0 data-[state=closed]:-translate-x-full";
|
|
160
|
+
|
|
161
|
+
/** Scrim opacity tracks the drag one-to-one, then hands back to the state fade. */
|
|
162
|
+
const scrimDragOpacity = dragging
|
|
163
|
+
? Math.max(0, 1 - dragOffset / Math.max(dragHeight.current, 1))
|
|
164
|
+
: undefined;
|
|
165
|
+
|
|
94
166
|
const node = (
|
|
95
167
|
<div
|
|
96
168
|
data-state={state}
|
|
97
|
-
className="fixed inset-0 data-[state=closed]:pointer-events-none"
|
|
169
|
+
className="fixed inset-0 overflow-hidden data-[state=closed]:pointer-events-none"
|
|
98
170
|
style={{ zIndex: "var(--z-modal, 1200)" }}
|
|
99
171
|
aria-hidden={open ? undefined : true}
|
|
100
172
|
>
|
|
101
173
|
<div
|
|
102
174
|
data-state={state}
|
|
103
175
|
aria-hidden="true"
|
|
104
|
-
className=
|
|
176
|
+
className={cn(
|
|
177
|
+
dragging ? "transition-none" : "transition-opacity duration-200 ease-out",
|
|
178
|
+
"fixed inset-0 bg-scrim/40 data-[state=open]:opacity-100 data-[state=closed]:opacity-0",
|
|
179
|
+
)}
|
|
180
|
+
style={scrimDragOpacity === undefined ? undefined : { opacity: scrimDragOpacity }}
|
|
105
181
|
/>
|
|
106
182
|
<div
|
|
107
183
|
ref={(el) => {
|
|
@@ -117,17 +193,40 @@ export const Drawer = React.forwardRef<HTMLDivElement, DrawerProps>(
|
|
|
117
193
|
data-side={side}
|
|
118
194
|
data-drawer=""
|
|
119
195
|
className={cn(
|
|
120
|
-
"fixed
|
|
121
|
-
|
|
122
|
-
? "right-0 border-l border-hairline data-[state=closed]:translate-x-full"
|
|
123
|
-
: "left-0 border-r border-hairline data-[state=closed]:-translate-x-full",
|
|
124
|
-
"data-[state=open]:translate-x-0 data-[state=closed]:invisible",
|
|
196
|
+
"fixed flex flex-col overflow-hidden bg-canvas text-ink transition ease-out data-[state=closed]:invisible",
|
|
197
|
+
sideClasses,
|
|
125
198
|
className,
|
|
126
199
|
)}
|
|
200
|
+
style={{
|
|
201
|
+
maxHeight: isBottom ? "90dvh" : undefined,
|
|
202
|
+
paddingBottom: isBottom ? "env(safe-area-inset-bottom, 0px)" : undefined,
|
|
203
|
+
transform:
|
|
204
|
+
isBottom && dragging && dragOffset > 0
|
|
205
|
+
? `translateY(${dragOffset}px)`
|
|
206
|
+
: undefined,
|
|
207
|
+
transitionDuration: dragging ? "0ms" : "240ms",
|
|
208
|
+
}}
|
|
127
209
|
{...rest}
|
|
128
210
|
>
|
|
211
|
+
{isBottom && showHandle && (
|
|
212
|
+
<div
|
|
213
|
+
aria-hidden="true"
|
|
214
|
+
onPointerDown={onHandlePointerDown}
|
|
215
|
+
onPointerMove={onHandlePointerMove}
|
|
216
|
+
onPointerUp={onHandlePointerUp}
|
|
217
|
+
onPointerCancel={onHandlePointerCancel}
|
|
218
|
+
className="flex shrink-0 cursor-grab touch-none select-none items-center justify-center pb-xs pt-sm active:cursor-grabbing"
|
|
219
|
+
>
|
|
220
|
+
<span className="h-1 w-10 rounded-full bg-hairline-strong" />
|
|
221
|
+
</div>
|
|
222
|
+
)}
|
|
129
223
|
{!hideHeader && (
|
|
130
|
-
<div
|
|
224
|
+
<div
|
|
225
|
+
className={cn(
|
|
226
|
+
"flex shrink-0 items-center justify-between gap-sm px-base pb-sm",
|
|
227
|
+
isBottom ? "pt-xs" : "pt-base",
|
|
228
|
+
)}
|
|
229
|
+
>
|
|
131
230
|
<div className="flex min-w-0 flex-1 items-center gap-sm">
|
|
132
231
|
{headerStart}
|
|
133
232
|
{hasTitle && (
|
|
@@ -8,6 +8,7 @@ import { Avatar } from "../Avatar";
|
|
|
8
8
|
import { Input } from "../Input";
|
|
9
9
|
import { Dropdown } from "../Dropdown";
|
|
10
10
|
import { DatePickerInput } from "../DatePickerInput";
|
|
11
|
+
import { MenuItem } from "../MenuItem";
|
|
11
12
|
|
|
12
13
|
const NAV: Array<{ label: string; icon: IconName }> = [
|
|
13
14
|
{ label: "Inbox", icon: "inbox" },
|
|
@@ -16,14 +17,23 @@ const NAV: Array<{ label: string; icon: IconName }> = [
|
|
|
16
17
|
{ label: "Views", icon: "layers" },
|
|
17
18
|
];
|
|
18
19
|
|
|
20
|
+
const PROJECT_ACTIONS: Array<{ label: string; icon: IconName }> = [
|
|
21
|
+
{ label: "Open project", icon: "box" },
|
|
22
|
+
{ label: "Project settings", icon: "settings" },
|
|
23
|
+
{ label: "Share project", icon: "users" },
|
|
24
|
+
{ label: "Archive project", icon: "archive" },
|
|
25
|
+
];
|
|
26
|
+
|
|
19
27
|
export default function DrawerPreview() {
|
|
20
28
|
const [navOpen, setNavOpen] = React.useState(false);
|
|
21
29
|
const [issueOpen, setIssueOpen] = React.useState(false);
|
|
30
|
+
const [sheetOpen, setSheetOpen] = React.useState(false);
|
|
22
31
|
const [active, setActive] = React.useState("Inbox");
|
|
23
32
|
const [title, setTitle] = React.useState("Create a habit tracker");
|
|
24
33
|
const [assignee, setAssignee] = React.useState<string | null>("me");
|
|
25
34
|
const [status, setStatus] = React.useState<string | null>("backlog");
|
|
26
35
|
const [due, setDue] = React.useState<Date | null>(new Date(2026, 2, 30));
|
|
36
|
+
const [lastAction, setLastAction] = React.useState<string | null>(null);
|
|
27
37
|
|
|
28
38
|
return (
|
|
29
39
|
<div className="w-full max-w-3xl mx-auto p-lg">
|
|
@@ -47,6 +57,23 @@ export default function DrawerPreview() {
|
|
|
47
57
|
</Button>
|
|
48
58
|
</div>
|
|
49
59
|
|
|
60
|
+
<div className="mt-md flex flex-wrap items-center justify-between gap-md rounded-xl border border-hairline bg-surface p-base">
|
|
61
|
+
<div className="min-w-0">
|
|
62
|
+
<p className="text-body-md text-ink">Habit tracker</p>
|
|
63
|
+
<p className="text-body-sm text-muted">
|
|
64
|
+
{lastAction ? `Last action: ${lastAction}` : "Bottom sheet project menu, drag the handle to dismiss"}
|
|
65
|
+
</p>
|
|
66
|
+
</div>
|
|
67
|
+
<Button
|
|
68
|
+
variant="secondary"
|
|
69
|
+
leadingIcon={<Icon name="ellipsis" size={16} />}
|
|
70
|
+
aria-expanded={sheetOpen}
|
|
71
|
+
onClick={() => setSheetOpen(true)}
|
|
72
|
+
>
|
|
73
|
+
Project actions
|
|
74
|
+
</Button>
|
|
75
|
+
</div>
|
|
76
|
+
|
|
50
77
|
<Drawer
|
|
51
78
|
open={navOpen}
|
|
52
79
|
onOpenChange={setNavOpen}
|
|
@@ -134,6 +161,41 @@ export default function DrawerPreview() {
|
|
|
134
161
|
<DatePickerInput aria-label="Due date" value={due} onValueChange={setDue} />
|
|
135
162
|
</div>
|
|
136
163
|
</Drawer>
|
|
164
|
+
|
|
165
|
+
<Drawer
|
|
166
|
+
open={sheetOpen}
|
|
167
|
+
onOpenChange={setSheetOpen}
|
|
168
|
+
side="bottom"
|
|
169
|
+
aria-label="Project actions"
|
|
170
|
+
closeLabel="Dismiss project actions"
|
|
171
|
+
headerStart={
|
|
172
|
+
<div className="flex min-w-0 flex-col">
|
|
173
|
+
<span className="truncate text-body-md text-ink">Habit tracker</span>
|
|
174
|
+
<span className="truncate text-body-sm text-muted">4 actions available</span>
|
|
175
|
+
</div>
|
|
176
|
+
}
|
|
177
|
+
bodyClassName="px-xs pb-xs pt-0"
|
|
178
|
+
>
|
|
179
|
+
<div
|
|
180
|
+
role="menu"
|
|
181
|
+
aria-label="Project actions"
|
|
182
|
+
className="flex flex-col gap-xxs"
|
|
183
|
+
>
|
|
184
|
+
{PROJECT_ACTIONS.map((action) => (
|
|
185
|
+
<MenuItem
|
|
186
|
+
key={action.label}
|
|
187
|
+
icon={action.icon}
|
|
188
|
+
className="h-11"
|
|
189
|
+
onClick={() => {
|
|
190
|
+
setLastAction(action.label);
|
|
191
|
+
setSheetOpen(false);
|
|
192
|
+
}}
|
|
193
|
+
>
|
|
194
|
+
{action.label}
|
|
195
|
+
</MenuItem>
|
|
196
|
+
))}
|
|
197
|
+
</div>
|
|
198
|
+
</Drawer>
|
|
137
199
|
</div>
|
|
138
200
|
);
|
|
139
201
|
}
|
|
@@ -70,6 +70,7 @@ export const Switch = React.forwardRef<HTMLInputElement, SwitchProps>(
|
|
|
70
70
|
};
|
|
71
71
|
|
|
72
72
|
const labelled = Boolean(label);
|
|
73
|
+
const hasDescription = Boolean(description);
|
|
73
74
|
|
|
74
75
|
return (
|
|
75
76
|
<label
|
|
@@ -86,13 +87,29 @@ export const Switch = React.forwardRef<HTMLInputElement, SwitchProps>(
|
|
|
86
87
|
.join(" ")}
|
|
87
88
|
>
|
|
88
89
|
{labelled ? (
|
|
89
|
-
<span
|
|
90
|
+
<span
|
|
91
|
+
className={[
|
|
92
|
+
"flex min-w-0 gap-md",
|
|
93
|
+
/* With a description the leading visual aligns to the first line;
|
|
94
|
+
with a single-line label it centers with that line. */
|
|
95
|
+
hasDescription ? "items-start" : "items-center",
|
|
96
|
+
].join(" ")}
|
|
97
|
+
>
|
|
90
98
|
{leading ? (
|
|
91
|
-
<span
|
|
99
|
+
<span
|
|
100
|
+
className={[
|
|
101
|
+
"inline-flex shrink-0 text-ink",
|
|
102
|
+
hasDescription ? "mt-xxs" : "",
|
|
103
|
+
]
|
|
104
|
+
.filter(Boolean)
|
|
105
|
+
.join(" ")}
|
|
106
|
+
>
|
|
107
|
+
{leading}
|
|
108
|
+
</span>
|
|
92
109
|
) : null}
|
|
93
110
|
<span className="flex min-w-0 flex-col">
|
|
94
111
|
<span className="text-body-md text-ink">{label}</span>
|
|
95
|
-
{
|
|
112
|
+
{hasDescription ? (
|
|
96
113
|
<span id={descId} className="text-body-sm text-muted">
|
|
97
114
|
{description}
|
|
98
115
|
</span>
|
|
@@ -8,16 +8,73 @@ export default function SwitchPreview() {
|
|
|
8
8
|
const [on, setOn] = React.useState(true);
|
|
9
9
|
const [small, setSmall] = React.useState(true);
|
|
10
10
|
|
|
11
|
+
const [tileA, setTileA] = React.useState(true);
|
|
12
|
+
const [tileB, setTileB] = React.useState(false);
|
|
13
|
+
const [tileC, setTileC] = React.useState(true);
|
|
14
|
+
|
|
11
15
|
return (
|
|
12
16
|
<div className="w-full max-w-3xl mx-auto p-lg space-y-lg">
|
|
13
|
-
<div className="
|
|
14
|
-
<
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
17
|
+
<div className="space-y-sm">
|
|
18
|
+
<p className="text-caption uppercase tracking-wide text-muted">
|
|
19
|
+
Leading visual, no description
|
|
20
|
+
</p>
|
|
21
|
+
<div className="divide-y divide-hairline-soft overflow-hidden rounded-lg border border-hairline bg-surface">
|
|
22
|
+
<div className="px-base py-md">
|
|
23
|
+
<Switch
|
|
24
|
+
label="Appearance"
|
|
25
|
+
leading={
|
|
26
|
+
<span className="inline-flex h-8 w-8 items-center justify-center rounded-full bg-surface-soft text-ink">
|
|
27
|
+
<Icon name="hash" size={16} />
|
|
28
|
+
</span>
|
|
29
|
+
}
|
|
30
|
+
checked={tileA}
|
|
31
|
+
onCheckedChange={setTileA}
|
|
32
|
+
/>
|
|
33
|
+
</div>
|
|
34
|
+
<div className="px-base py-md">
|
|
35
|
+
<Switch
|
|
36
|
+
label="Notifications"
|
|
37
|
+
leading={
|
|
38
|
+
<span className="inline-flex h-8 w-8 items-center justify-center rounded-full bg-surface-soft text-ink">
|
|
39
|
+
<Icon name="hash" size={16} />
|
|
40
|
+
</span>
|
|
41
|
+
}
|
|
42
|
+
checked={tileB}
|
|
43
|
+
onCheckedChange={setTileB}
|
|
44
|
+
/>
|
|
45
|
+
</div>
|
|
46
|
+
<div className="px-base py-md">
|
|
47
|
+
<Switch
|
|
48
|
+
label="Large leading visual with a longer single-line label"
|
|
49
|
+
leading={
|
|
50
|
+
<span className="inline-flex h-8 w-8 items-center justify-center rounded-full bg-surface-soft text-ink">
|
|
51
|
+
<Icon name="hash" size={16} />
|
|
52
|
+
</span>
|
|
53
|
+
}
|
|
54
|
+
checked={tileC}
|
|
55
|
+
onCheckedChange={setTileC}
|
|
56
|
+
/>
|
|
57
|
+
</div>
|
|
58
|
+
</div>
|
|
59
|
+
</div>
|
|
60
|
+
|
|
61
|
+
<div className="space-y-sm">
|
|
62
|
+
<p className="text-caption uppercase tracking-wide text-muted">
|
|
63
|
+
With description (top aligned)
|
|
64
|
+
</p>
|
|
65
|
+
<div className="max-w-md rounded-lg border border-hairline bg-surface px-base py-md">
|
|
66
|
+
<Switch
|
|
67
|
+
label="Channel notifications"
|
|
68
|
+
description="Get updates in a team channel"
|
|
69
|
+
leading={
|
|
70
|
+
<span className="inline-flex h-8 w-8 items-center justify-center rounded-full bg-surface-soft text-ink">
|
|
71
|
+
<Icon name="hash" size={16} />
|
|
72
|
+
</span>
|
|
73
|
+
}
|
|
74
|
+
checked={channel}
|
|
75
|
+
onCheckedChange={setChannel}
|
|
76
|
+
/>
|
|
77
|
+
</div>
|
|
21
78
|
</div>
|
|
22
79
|
|
|
23
80
|
<div className="flex flex-wrap items-end gap-xl">
|