oneslash-design-system 2.6.0 → 2.7.1
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/list.d.ts +2 -1
- package/dist/components/list.jsx +10 -4
- package/dist/components/select.jsx +49 -12
- package/dist/stories/List.stories.d.ts +9 -0
- package/dist/stories/List.stories.jsx +27 -0
- package/dist/stories/Select.stories.d.ts +1 -0
- package/dist/stories/Select.stories.jsx +59 -0
- package/package.json +1 -1
|
@@ -3,7 +3,8 @@ interface ListProps {
|
|
|
3
3
|
items: React.ReactNode[];
|
|
4
4
|
size?: 'body1' | 'body2';
|
|
5
5
|
tone?: 'primary' | 'secondary';
|
|
6
|
+
marker?: 'none' | 'dot' | 'number';
|
|
6
7
|
className?: string;
|
|
7
8
|
}
|
|
8
|
-
export default function List({ items, size, tone, className }: ListProps): React.JSX.Element;
|
|
9
|
+
export default function List({ items, size, tone, marker, className }: ListProps): React.JSX.Element;
|
|
9
10
|
export {};
|
package/dist/components/list.jsx
CHANGED
|
@@ -1,10 +1,16 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
var sizes = { body1: 'text-body1', body2: 'text-body2' };
|
|
3
3
|
var tones = { primary: 'text-fg-primary', secondary: 'text-fg-secondary' };
|
|
4
|
-
//
|
|
4
|
+
// Markers are the browser's own, set outside the text so a wrapped line stays
|
|
5
|
+
// aligned; they take the list's text color, so they follow `tone`.
|
|
6
|
+
var markers = { dot: 'list-disc pl-xlarge', number: 'list-decimal pl-xlarge' };
|
|
7
|
+
// A list, one line of text per item, a little apart. `marker` puts a dot or a
|
|
8
|
+
// number before each item; numbers use an <ol>.
|
|
5
9
|
export default function List(_a) {
|
|
6
|
-
var items = _a.items, _b = _a.size, size = _b === void 0 ? 'body2' : _b, _c = _a.tone, tone = _c === void 0 ? 'primary' : _c, _d = _a.className, className =
|
|
7
|
-
|
|
10
|
+
var items = _a.items, _b = _a.size, size = _b === void 0 ? 'body2' : _b, _c = _a.tone, tone = _c === void 0 ? 'primary' : _c, _d = _a.marker, marker = _d === void 0 ? 'none' : _d, _e = _a.className, className = _e === void 0 ? '' : _e;
|
|
11
|
+
var Tag = marker === 'number' ? 'ol' : 'ul';
|
|
12
|
+
var markerClass = marker === 'none' ? '' : "".concat(markers[marker], " ");
|
|
13
|
+
return (<Tag className={"flex flex-col gap-medium ".concat(markerClass).concat(sizes[size], " ").concat(tones[tone], " ").concat(className)}>
|
|
8
14
|
{items.map(function (item, i) { return (<li key={i}>{item}</li>); })}
|
|
9
|
-
</
|
|
15
|
+
</Tag>);
|
|
10
16
|
}
|
|
@@ -8,20 +8,54 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
8
8
|
}
|
|
9
9
|
return to.concat(ar || Array.prototype.slice.call(from));
|
|
10
10
|
};
|
|
11
|
-
import React, { useState, useEffect, useRef, useId } from 'react';
|
|
11
|
+
import React, { useState, useEffect, useRef, useId, useCallback } from 'react';
|
|
12
|
+
import { createPortal } from 'react-dom';
|
|
13
|
+
import { usePopper } from 'react-popper';
|
|
12
14
|
import * as LucideIcons from 'lucide-react';
|
|
13
15
|
import { ChevronDown } from 'lucide-react';
|
|
14
16
|
import Menu from './menu';
|
|
15
17
|
import MenuItem from './menuItem';
|
|
16
18
|
import { focusRing, overlayHidden, overlayTransition, overlayVisible, stateTransition } from './sharedStyles';
|
|
17
19
|
import { useOverlayTransition } from './useOverlayTransition';
|
|
20
|
+
// Module-level so the options keep one identity: react-popper re-runs on every
|
|
21
|
+
// render when a modifier's functions are new, which loops with its own state updates.
|
|
22
|
+
var popperOptions = {
|
|
23
|
+
placement: 'bottom-start',
|
|
24
|
+
modifiers: [
|
|
25
|
+
{ name: 'offset', options: { offset: [0, 4] } }, // Same 4px gap as Popover and Tooltip
|
|
26
|
+
{
|
|
27
|
+
// Match the trigger's width (which is the width prop when one is set)
|
|
28
|
+
name: 'sameWidth',
|
|
29
|
+
enabled: true,
|
|
30
|
+
phase: 'beforeWrite',
|
|
31
|
+
requires: ['computeStyles'],
|
|
32
|
+
fn: function (_a) {
|
|
33
|
+
var state = _a.state;
|
|
34
|
+
state.styles.popper.width = "".concat(state.rects.reference.width, "px");
|
|
35
|
+
},
|
|
36
|
+
effect: function (_a) {
|
|
37
|
+
var state = _a.state;
|
|
38
|
+
state.elements.popper.style.width = "".concat(state.elements.reference.offsetWidth, "px");
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
],
|
|
42
|
+
};
|
|
18
43
|
export default function Select(_a) {
|
|
19
|
-
var
|
|
20
|
-
var
|
|
44
|
+
var _b, _c;
|
|
45
|
+
var value = _a.value, options = _a.options, onChange = _a.onChange, _d = _a.disabled, disabled = _d === void 0 ? false : _d, _e = _a.placeholder, placeholder = _e === void 0 ? 'Label' : _e, decoIconName = _a.decoIconName, width = _a.width, _f = _a.multiple, multiple = _f === void 0 ? false : _f, _g = _a.className, className = _g === void 0 ? '' : _g;
|
|
46
|
+
var _h = useState(false), isOpen = _h[0], setIsOpen = _h[1];
|
|
21
47
|
// Option highlighted by the keyboard; focus itself stays on the trigger
|
|
22
|
-
var
|
|
23
|
-
var
|
|
48
|
+
var _j = useState(-1), activeIndex = _j[0], setActiveIndex = _j[1];
|
|
49
|
+
var _k = useOverlayTransition(isOpen), menuMounted = _k.mounted, menuVisible = _k.visible;
|
|
24
50
|
var selectRef = useRef(null);
|
|
51
|
+
// The listbox renders in a portal so no ancestor's overflow can clip it
|
|
52
|
+
var _l = useState(null), listElement = _l[0], setListElement = _l[1];
|
|
53
|
+
var _m = useState(null), triggerElement = _m[0], setTriggerElement = _m[1];
|
|
54
|
+
var setTrigger = useCallback(function (el) {
|
|
55
|
+
selectRef.current = el;
|
|
56
|
+
setTriggerElement(el);
|
|
57
|
+
}, []);
|
|
58
|
+
var _o = usePopper(triggerElement, listElement, popperOptions), styles = _o.styles, attributes = _o.attributes;
|
|
25
59
|
var menuRef = useRef(null);
|
|
26
60
|
var listboxId = useId();
|
|
27
61
|
var optionId = function (index) { return "".concat(listboxId, "-option-").concat(index); };
|
|
@@ -175,7 +209,7 @@ export default function Select(_a) {
|
|
|
175
209
|
};
|
|
176
210
|
return (<div className={"relative ".concat(className)} style={{ width: width || '100%' }}>
|
|
177
211
|
{/* Select Button */}
|
|
178
|
-
<div ref={
|
|
212
|
+
<div ref={setTrigger} role="combobox" aria-haspopup="listbox" aria-expanded={isOpen} aria-controls={listboxId} aria-activedescendant={isOpen && activeIndex >= 0 ? optionId(activeIndex) : undefined} aria-disabled={disabled || undefined} className={"\n rounded-control\n ".concat(getStateStyles(), "\n ").concat(disabled ? 'cursor-not-allowed' : 'cursor-pointer', "\n ").concat(stateTransition, "\n ").concat(focusRing, "\n ")} onClick={handleToggle} tabIndex={disabled ? -1 : 0} onKeyDown={handleKeyDown}>
|
|
179
213
|
{/* Inner Content Container; 7px vertical padding makes the control 40px like Button and TextField */}
|
|
180
214
|
<div className={"flex items-center justify-between px-2 py-[7px] ".concat(getTextColor())}>
|
|
181
215
|
{/* Content Container */}
|
|
@@ -194,12 +228,15 @@ export default function Select(_a) {
|
|
|
194
228
|
</div>
|
|
195
229
|
</div>
|
|
196
230
|
|
|
197
|
-
{/* Dropdown Menu */}
|
|
198
|
-
{menuMounted && (<div id={listboxId} role="listbox" aria-multiselectable={multiple || undefined} className=
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
231
|
+
{/* Dropdown Menu: portaled to the body, positioned by Popper (flips above when there is no room below) */}
|
|
232
|
+
{menuMounted && createPortal(<div id={listboxId} ref={setListElement} role="listbox" aria-multiselectable={multiple || undefined} style={styles.popper} {...attributes.popper} className="z-[var(--os-z-overlay)]">
|
|
233
|
+
{/* Popper owns the outer transform, so the fade and scale go on this inner panel */}
|
|
234
|
+
<div className={"".concat(((_c = (_b = attributes.popper) === null || _b === void 0 ? void 0 : _b['data-popper-placement']) === null || _c === void 0 ? void 0 : _c.startsWith('top')) ? 'origin-bottom' : 'origin-top', " ").concat(overlayTransition, " ").concat(menuVisible ? overlayVisible : overlayHidden)}>
|
|
235
|
+
<Menu ref={menuRef} width="100%" className="max-h-[320px] overflow-y-auto">
|
|
236
|
+
{options.map(function (option, index) { return (<MenuItem key={option.value} id={optionId(index)} role="option" tabIndex={-1} isActive={index === activeIndex} label={option.label} iconName={option.iconName} isSelected={isSelected(option.value)} onClick={function () { return handleSelect(option.value); }} className="w-full"/>); })}
|
|
237
|
+
</Menu>
|
|
238
|
+
</div>
|
|
239
|
+
</div>, document.body)}
|
|
203
240
|
</div>);
|
|
204
241
|
}
|
|
205
242
|
export { Select };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from "@storybook/react";
|
|
2
|
+
import List from "../components/list";
|
|
3
|
+
declare const meta: Meta<typeof List>;
|
|
4
|
+
export default meta;
|
|
5
|
+
type Story = StoryObj<typeof List>;
|
|
6
|
+
export declare const None: Story;
|
|
7
|
+
export declare const Dot: Story;
|
|
8
|
+
export declare const Number: Story;
|
|
9
|
+
export declare const SecondaryDot: Story;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import List from "../components/list";
|
|
3
|
+
var items = [
|
|
4
|
+
"Short item",
|
|
5
|
+
"A longer item that is long enough to wrap onto a second line in a narrow column, to show the marker staying put.",
|
|
6
|
+
"Last item",
|
|
7
|
+
];
|
|
8
|
+
var meta = {
|
|
9
|
+
title: "Components/List",
|
|
10
|
+
component: List,
|
|
11
|
+
args: { items: items },
|
|
12
|
+
argTypes: {
|
|
13
|
+
marker: { control: "select", options: ["none", "dot", "number"] },
|
|
14
|
+
size: { control: "select", options: ["body1", "body2"] },
|
|
15
|
+
tone: { control: "select", options: ["primary", "secondary"] },
|
|
16
|
+
},
|
|
17
|
+
decorators: [
|
|
18
|
+
function (Story) { return (<div style={{ width: "280px", padding: "16px" }}>
|
|
19
|
+
<Story />
|
|
20
|
+
</div>); },
|
|
21
|
+
],
|
|
22
|
+
};
|
|
23
|
+
export default meta;
|
|
24
|
+
export var None = { args: { marker: "none" } };
|
|
25
|
+
export var Dot = { args: { marker: "dot" } };
|
|
26
|
+
export var Number = { args: { marker: "number" } };
|
|
27
|
+
export var SecondaryDot = { args: { marker: "dot", tone: "secondary" } };
|
|
@@ -1,3 +1,39 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
11
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
12
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
13
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
14
|
+
function step(op) {
|
|
15
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
16
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
17
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
18
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
19
|
+
switch (op[0]) {
|
|
20
|
+
case 0: case 1: t = op; break;
|
|
21
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
22
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
23
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
24
|
+
default:
|
|
25
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
26
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
27
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
28
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
29
|
+
if (t[2]) _.ops.pop();
|
|
30
|
+
_.trys.pop(); continue;
|
|
31
|
+
}
|
|
32
|
+
op = body.call(thisArg, _);
|
|
33
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
34
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
35
|
+
}
|
|
36
|
+
};
|
|
1
37
|
import React, { useState } from "react";
|
|
2
38
|
import Select from "../components/select";
|
|
3
39
|
var meta = {
|
|
@@ -83,3 +119,26 @@ export var MultiSelect = {
|
|
|
83
119
|
width: 250,
|
|
84
120
|
},
|
|
85
121
|
};
|
|
122
|
+
// The list is portaled, so a clipping ancestor (overflow hidden/auto) must not cut it off.
|
|
123
|
+
export var InsideClippingContainer = {
|
|
124
|
+
render: function (args) { return (<div className="overflow-hidden rounded-control border border-misc-divider p-4" style={{ width: 320, height: 120 }}>
|
|
125
|
+
<SelectWrapper {...args}/>
|
|
126
|
+
</div>); },
|
|
127
|
+
play: function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
|
|
128
|
+
var _c;
|
|
129
|
+
var canvasElement = _b.canvasElement;
|
|
130
|
+
return __generator(this, function (_d) {
|
|
131
|
+
(_c = canvasElement.querySelector('[role="combobox"]')) === null || _c === void 0 ? void 0 : _c.click();
|
|
132
|
+
return [2 /*return*/];
|
|
133
|
+
});
|
|
134
|
+
}); },
|
|
135
|
+
args: {
|
|
136
|
+
placeholder: "Select an option",
|
|
137
|
+
options: [
|
|
138
|
+
{ value: "option1", label: "Option 1" },
|
|
139
|
+
{ value: "option2", label: "Option 2" },
|
|
140
|
+
{ value: "option3", label: "Option 3" },
|
|
141
|
+
{ value: "option4", label: "Option 4" },
|
|
142
|
+
],
|
|
143
|
+
},
|
|
144
|
+
};
|