@assembly-js/design-system 3.1.0 → 3.1.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/esm/components/Toolbar/Toolbar.js +12 -3
- package/dist/esm/components/Toolbar/ToolbarDropdown.js +181 -0
- package/dist/esm/components/Typography/Body.js +2 -1
- package/dist/esm/types/components/Toolbar/Toolbar.stories.d.ts +7 -0
- package/dist/esm/types/components/Toolbar/ToolbarDropdown.d.ts +7 -0
- package/dist/esm/types/components/Toolbar/types.d.ts +1 -0
- package/dist/esm/types/components/Typography/Base.d.ts +2 -2
- package/dist/esm/types/components/Typography/Base.stories.d.ts +1 -1
- package/dist/esm/types/tsconfig.tsbuildinfo +1 -1
- package/dist/styles/main.css +1 -1
- package/dist/types/components/Toolbar/Toolbar.stories.d.ts +7 -0
- package/dist/types/components/Toolbar/ToolbarDropdown.d.ts +7 -0
- package/dist/types/components/Toolbar/types.d.ts +1 -0
- package/dist/types/components/Typography/Base.d.ts +2 -2
- package/dist/types/components/Typography/Base.stories.d.ts +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/dist/umd/components/Toolbar/Toolbar.js +17 -9
- package/dist/umd/components/Toolbar/ToolbarDropdown.js +199 -0
- package/dist/umd/components/Typography/Body.js +2 -1
- package/dist/umd/types/components/Toolbar/Toolbar.stories.d.ts +7 -0
- package/dist/umd/types/components/Toolbar/ToolbarDropdown.d.ts +7 -0
- package/dist/umd/types/components/Toolbar/types.d.ts +1 -0
- package/dist/umd/types/components/Typography/Base.d.ts +2 -2
- package/dist/umd/types/components/Typography/Base.stories.d.ts +1 -1
- package/dist/umd/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
|
@@ -6,12 +6,14 @@ function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object
|
|
|
6
6
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
7
7
|
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
8
8
|
import React from "react";
|
|
9
|
+
import { Fragment } from 'react';
|
|
9
10
|
import { cva } from 'cva';
|
|
10
11
|
import { useToolbar } from "./ToolbarContext";
|
|
11
12
|
import { cn } from "../../common/utils";
|
|
12
13
|
import { Icon } from "../Icon";
|
|
13
14
|
import { Tooltip } from "../Tooltip/Tooltip";
|
|
14
15
|
import { Body } from "../Typography";
|
|
16
|
+
import { ToolbarDropdown } from "./ToolbarDropdown";
|
|
15
17
|
var toolbarVariants = cva({
|
|
16
18
|
base: cn('cop-inline-flex cop-items-center cop-gap-0.5 cop-p-1'),
|
|
17
19
|
variants: {
|
|
@@ -122,7 +124,13 @@ var ToolbarGroup = function ToolbarGroup(_ref2) {
|
|
|
122
124
|
variant: variant
|
|
123
125
|
});
|
|
124
126
|
}
|
|
125
|
-
|
|
127
|
+
if (action.type === 'dropdown') {
|
|
128
|
+
return /*#__PURE__*/React.createElement(ToolbarDropdown, {
|
|
129
|
+
key: action.id,
|
|
130
|
+
action: action,
|
|
131
|
+
variant: variant
|
|
132
|
+
});
|
|
133
|
+
}
|
|
126
134
|
return null;
|
|
127
135
|
}));
|
|
128
136
|
};
|
|
@@ -149,8 +157,9 @@ export var Toolbar = function Toolbar(_ref3) {
|
|
|
149
157
|
"aria-label": "Formatting toolbar"
|
|
150
158
|
}, filteredConfig.map(function (item, index) {
|
|
151
159
|
if (item.type === 'group') {
|
|
152
|
-
return /*#__PURE__*/React.createElement(
|
|
153
|
-
key: item.id
|
|
160
|
+
return /*#__PURE__*/React.createElement(Fragment, {
|
|
161
|
+
key: item.id
|
|
162
|
+
}, /*#__PURE__*/React.createElement(ToolbarGroup, {
|
|
154
163
|
group: item,
|
|
155
164
|
variant: variant
|
|
156
165
|
}), filteredConfig.length > 1 && index < filteredConfig.length - 1 && /*#__PURE__*/React.createElement(ToolbarSeparator, null));
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
// This file is generated by a script. Do not edit this file directly.
|
|
2
|
+
function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
|
|
3
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
4
|
+
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
5
|
+
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
6
|
+
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
7
|
+
function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
|
|
8
|
+
import React from "react";
|
|
9
|
+
import { useState, useRef, useEffect, useCallback } from 'react';
|
|
10
|
+
import { cva } from 'cva';
|
|
11
|
+
import { cn } from "../../common/utils";
|
|
12
|
+
import { Icon } from "../Icon";
|
|
13
|
+
import { useToolbar } from "./ToolbarContext";
|
|
14
|
+
var buttonVariants = cva({
|
|
15
|
+
base: cn('cop-flex cop-items-center cop-justify-center cop-gap-1', 'cop-h-6 cop-px-1.5 cop-rounded', 'cop-border-none cop-cursor-pointer', 'hover:cop-bg-gray-150 active:cop-bg-gray-200'),
|
|
16
|
+
variants: {
|
|
17
|
+
variant: {
|
|
18
|
+
highlight: 'cop-bg-white',
|
|
19
|
+
sticky: 'cop-bg-gray-100'
|
|
20
|
+
},
|
|
21
|
+
isOpen: {
|
|
22
|
+
"true": '!cop-bg-gray-200',
|
|
23
|
+
"false": ''
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
defaultVariants: {
|
|
27
|
+
variant: 'highlight',
|
|
28
|
+
isOpen: false
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
var iconStyles = cn('cop-flex cop-items-center cop-justify-center cop-h-4 cop-w-4 cop-text-gray-700');
|
|
32
|
+
var dropdownMenuStyles = cn('cop-absolute cop-top-full cop-left-0 cop-mt-1 cop-z-50', 'cop-flex cop-w-[256px] cop-flex-col cop-bg-white', 'cop-rounded cop-border cop-border-solid cop-border-secondary', 'cop-py-1 cop-shadow-popover-50');
|
|
33
|
+
var dropdownOptionStyles = cn('cop-flex cop-cursor-pointer cop-items-center cop-gap-2', 'cop-border-none cop-bg-white', 'cop-px-2 cop-py-1.5 cop-outline-none', 'hover:!cop-bg-gray-100');
|
|
34
|
+
var dropdownOptionFocusedStyles = '!cop-bg-gray-100';
|
|
35
|
+
var dropdownOptionIconStyles = cn('cop-h-4 cop-w-4 cop-text-gray-700');
|
|
36
|
+
var dropdownOptionLabelStyles = cn('cop-text-base');
|
|
37
|
+
export var ToolbarDropdown = function ToolbarDropdown(_ref) {
|
|
38
|
+
var _ref2;
|
|
39
|
+
var action = _ref.action,
|
|
40
|
+
variant = _ref.variant;
|
|
41
|
+
var _useToolbar = useToolbar(),
|
|
42
|
+
onAction = _useToolbar.onAction;
|
|
43
|
+
var _useState = useState(null),
|
|
44
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
45
|
+
selectedOption = _useState2[0],
|
|
46
|
+
setSelectedOption = _useState2[1];
|
|
47
|
+
var _useState3 = useState(false),
|
|
48
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
49
|
+
isOpen = _useState4[0],
|
|
50
|
+
setIsOpen = _useState4[1];
|
|
51
|
+
var _useState5 = useState(-1),
|
|
52
|
+
_useState6 = _slicedToArray(_useState5, 2),
|
|
53
|
+
focusedIndex = _useState6[0],
|
|
54
|
+
setFocusedIndex = _useState6[1];
|
|
55
|
+
var containerRef = useRef(null);
|
|
56
|
+
var menuRef = useRef(null);
|
|
57
|
+
var options = action.options;
|
|
58
|
+
var displayOption = (_ref2 = selectedOption !== null && selectedOption !== void 0 ? selectedOption : options[0]) !== null && _ref2 !== void 0 ? _ref2 : null;
|
|
59
|
+
|
|
60
|
+
// Close on outside click
|
|
61
|
+
useEffect(function () {
|
|
62
|
+
if (!isOpen) return;
|
|
63
|
+
var handleClickOutside = function handleClickOutside(event) {
|
|
64
|
+
if (containerRef.current && !containerRef.current.contains(event.target)) {
|
|
65
|
+
setIsOpen(false);
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
document.addEventListener('mousedown', handleClickOutside);
|
|
69
|
+
return function () {
|
|
70
|
+
return document.removeEventListener('mousedown', handleClickOutside);
|
|
71
|
+
};
|
|
72
|
+
}, [isOpen]);
|
|
73
|
+
|
|
74
|
+
// Focus menu and reset index when opening/closing
|
|
75
|
+
useEffect(function () {
|
|
76
|
+
if (isOpen) {
|
|
77
|
+
var _menuRef$current;
|
|
78
|
+
setFocusedIndex(0);
|
|
79
|
+
(_menuRef$current = menuRef.current) === null || _menuRef$current === void 0 || _menuRef$current.focus();
|
|
80
|
+
} else {
|
|
81
|
+
setFocusedIndex(-1);
|
|
82
|
+
}
|
|
83
|
+
}, [isOpen]);
|
|
84
|
+
var handleSelect = function handleSelect(option) {
|
|
85
|
+
setSelectedOption(option);
|
|
86
|
+
onAction({
|
|
87
|
+
id: action.id,
|
|
88
|
+
action: action.action,
|
|
89
|
+
metadata: {
|
|
90
|
+
value: option.value
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
setIsOpen(false);
|
|
94
|
+
};
|
|
95
|
+
var handleKeyDown = useCallback(function (e) {
|
|
96
|
+
switch (e.key) {
|
|
97
|
+
case 'ArrowDown':
|
|
98
|
+
{
|
|
99
|
+
e.preventDefault();
|
|
100
|
+
setFocusedIndex(function (prev) {
|
|
101
|
+
return prev < options.length - 1 ? prev + 1 : 0;
|
|
102
|
+
});
|
|
103
|
+
break;
|
|
104
|
+
}
|
|
105
|
+
case 'ArrowUp':
|
|
106
|
+
{
|
|
107
|
+
e.preventDefault();
|
|
108
|
+
setFocusedIndex(function (prev) {
|
|
109
|
+
return prev > 0 ? prev - 1 : options.length - 1;
|
|
110
|
+
});
|
|
111
|
+
break;
|
|
112
|
+
}
|
|
113
|
+
case 'Enter':
|
|
114
|
+
case ' ':
|
|
115
|
+
{
|
|
116
|
+
e.preventDefault();
|
|
117
|
+
var focusedOption = options[focusedIndex];
|
|
118
|
+
if (focusedOption) {
|
|
119
|
+
handleSelect(focusedOption);
|
|
120
|
+
}
|
|
121
|
+
break;
|
|
122
|
+
}
|
|
123
|
+
case 'Escape':
|
|
124
|
+
{
|
|
125
|
+
e.preventDefault();
|
|
126
|
+
setIsOpen(false);
|
|
127
|
+
break;
|
|
128
|
+
}
|
|
129
|
+
default:
|
|
130
|
+
break;
|
|
131
|
+
}
|
|
132
|
+
}, [options, focusedIndex]);
|
|
133
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
134
|
+
ref: containerRef,
|
|
135
|
+
className: "cop-relative"
|
|
136
|
+
}, /*#__PURE__*/React.createElement("button", {
|
|
137
|
+
type: "button",
|
|
138
|
+
className: cn(buttonVariants({
|
|
139
|
+
variant: variant,
|
|
140
|
+
isOpen: isOpen
|
|
141
|
+
})),
|
|
142
|
+
onClick: function onClick() {
|
|
143
|
+
return setIsOpen(!isOpen);
|
|
144
|
+
},
|
|
145
|
+
"aria-label": action.label,
|
|
146
|
+
"aria-expanded": isOpen,
|
|
147
|
+
"aria-haspopup": "listbox"
|
|
148
|
+
}, displayOption !== null && displayOption !== void 0 && displayOption.icon ? /*#__PURE__*/React.createElement(Icon, {
|
|
149
|
+
className: iconStyles,
|
|
150
|
+
icon: displayOption.icon
|
|
151
|
+
}) : /*#__PURE__*/React.createElement("span", {
|
|
152
|
+
className: "cop-text-xs cop-text-gray-700"
|
|
153
|
+
}, displayOption === null || displayOption === void 0 ? void 0 : displayOption.label), /*#__PURE__*/React.createElement(Icon, {
|
|
154
|
+
className: "cop-h-[10px] cop-w-[10px] cop-text-gray-700",
|
|
155
|
+
icon: "ChevronDown"
|
|
156
|
+
})), isOpen && /*#__PURE__*/React.createElement("div", {
|
|
157
|
+
ref: menuRef,
|
|
158
|
+
className: dropdownMenuStyles,
|
|
159
|
+
role: "listbox",
|
|
160
|
+
"aria-label": action.label,
|
|
161
|
+
tabIndex: -1,
|
|
162
|
+
onKeyDown: handleKeyDown
|
|
163
|
+
}, options.map(function (option, index) {
|
|
164
|
+
return /*#__PURE__*/React.createElement("button", {
|
|
165
|
+
key: option.value,
|
|
166
|
+
type: "button",
|
|
167
|
+
className: cn(dropdownOptionStyles, focusedIndex === index && dropdownOptionFocusedStyles),
|
|
168
|
+
role: "option",
|
|
169
|
+
"aria-selected": (selectedOption === null || selectedOption === void 0 ? void 0 : selectedOption.value) === option.value,
|
|
170
|
+
tabIndex: focusedIndex === index ? 0 : -1,
|
|
171
|
+
onClick: function onClick() {
|
|
172
|
+
return handleSelect(option);
|
|
173
|
+
}
|
|
174
|
+
}, option.icon && /*#__PURE__*/React.createElement(Icon, {
|
|
175
|
+
className: dropdownOptionIconStyles,
|
|
176
|
+
icon: option.icon
|
|
177
|
+
}), /*#__PURE__*/React.createElement("span", {
|
|
178
|
+
className: dropdownOptionLabelStyles
|
|
179
|
+
}, option.label));
|
|
180
|
+
})));
|
|
181
|
+
};
|
|
@@ -8,6 +8,12 @@ declare const meta: {
|
|
|
8
8
|
config?: ActionConfig[];
|
|
9
9
|
}) => import("react").JSX.Element;
|
|
10
10
|
tags: string[];
|
|
11
|
+
argTypes: {
|
|
12
|
+
variant: {
|
|
13
|
+
control: "select";
|
|
14
|
+
options: string[];
|
|
15
|
+
};
|
|
16
|
+
};
|
|
11
17
|
parameters: {
|
|
12
18
|
docs: {
|
|
13
19
|
description: {
|
|
@@ -25,3 +31,4 @@ export declare const Highlight: Story;
|
|
|
25
31
|
export declare const Sticky: Story;
|
|
26
32
|
export declare const MultipleGroups: Story;
|
|
27
33
|
export declare const WithTooltips: Story;
|
|
34
|
+
export declare const ToolbarWithDropdownActions: Story;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import type { DropdownActionConfig } from './types';
|
|
3
|
+
export interface ToolbarDropdownProps {
|
|
4
|
+
action: DropdownActionConfig;
|
|
5
|
+
variant: 'highlight' | 'sticky';
|
|
6
|
+
}
|
|
7
|
+
export declare const ToolbarDropdown: ({ action, variant }: ToolbarDropdownProps) => import("react").JSX.Element;
|
|
@@ -53,7 +53,7 @@ export declare const Base: ({ children, className, leading, size, variant, tag,
|
|
|
53
53
|
variant: keyof typeof VARIANT_CLASSNAMES;
|
|
54
54
|
tag: 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6' | 'p' | 'div' | 'span';
|
|
55
55
|
weight: WeightClassNames;
|
|
56
|
-
/** Used
|
|
57
|
-
'data-typography'?:
|
|
56
|
+
/** Used by consumers to target typography components with CSS selectors */
|
|
57
|
+
'data-typography'?: string;
|
|
58
58
|
}) => React.JSX.Element;
|
|
59
59
|
export {};
|
|
@@ -10,7 +10,7 @@ declare const meta: {
|
|
|
10
10
|
variant: "display" | "body" | "heading";
|
|
11
11
|
tag: "p" | "h1" | "h2" | "h3" | "h4" | "h5" | "h6" | "div" | "span";
|
|
12
12
|
weight: "bold" | "semibold" | "medium" | "regular" | "light";
|
|
13
|
-
'data-typography'?:
|
|
13
|
+
'data-typography'?: string | undefined;
|
|
14
14
|
}) => import("react").JSX.Element;
|
|
15
15
|
tags: string[];
|
|
16
16
|
};
|