@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.
Files changed (26) hide show
  1. package/dist/esm/components/Toolbar/Toolbar.js +12 -3
  2. package/dist/esm/components/Toolbar/ToolbarDropdown.js +181 -0
  3. package/dist/esm/components/Typography/Body.js +2 -1
  4. package/dist/esm/types/components/Toolbar/Toolbar.stories.d.ts +7 -0
  5. package/dist/esm/types/components/Toolbar/ToolbarDropdown.d.ts +7 -0
  6. package/dist/esm/types/components/Toolbar/types.d.ts +1 -0
  7. package/dist/esm/types/components/Typography/Base.d.ts +2 -2
  8. package/dist/esm/types/components/Typography/Base.stories.d.ts +1 -1
  9. package/dist/esm/types/tsconfig.tsbuildinfo +1 -1
  10. package/dist/styles/main.css +1 -1
  11. package/dist/types/components/Toolbar/Toolbar.stories.d.ts +7 -0
  12. package/dist/types/components/Toolbar/ToolbarDropdown.d.ts +7 -0
  13. package/dist/types/components/Toolbar/types.d.ts +1 -0
  14. package/dist/types/components/Typography/Base.d.ts +2 -2
  15. package/dist/types/components/Typography/Base.stories.d.ts +1 -1
  16. package/dist/types/tsconfig.tsbuildinfo +1 -1
  17. package/dist/umd/components/Toolbar/Toolbar.js +17 -9
  18. package/dist/umd/components/Toolbar/ToolbarDropdown.js +199 -0
  19. package/dist/umd/components/Typography/Body.js +2 -1
  20. package/dist/umd/types/components/Toolbar/Toolbar.stories.d.ts +7 -0
  21. package/dist/umd/types/components/Toolbar/ToolbarDropdown.d.ts +7 -0
  22. package/dist/umd/types/components/Toolbar/types.d.ts +1 -0
  23. package/dist/umd/types/components/Typography/Base.d.ts +2 -2
  24. package/dist/umd/types/components/Typography/Base.stories.d.ts +1 -1
  25. package/dist/umd/types/tsconfig.tsbuildinfo +1 -1
  26. package/package.json +1 -1
@@ -1,25 +1,26 @@
1
1
  // This file is generated by a script. Do not edit this file directly.
2
2
  (function (global, factory) {
3
3
  if (typeof define === "function" && define.amd) {
4
- define(["exports", "react", "cva", "./ToolbarContext", "../../common/utils", "../Icon", "../Tooltip/Tooltip", "../Typography"], factory);
4
+ define(["exports", "react", "cva", "./ToolbarContext", "../../common/utils", "../Icon", "../Tooltip/Tooltip", "../Typography", "./ToolbarDropdown"], factory);
5
5
  } else if (typeof exports !== "undefined") {
6
- factory(exports, require("react"), require("cva"), require("./ToolbarContext"), require("../../common/utils"), require("../Icon"), require("../Tooltip/Tooltip"), require("../Typography"));
6
+ factory(exports, require("react"), require("cva"), require("./ToolbarContext"), require("../../common/utils"), require("../Icon"), require("../Tooltip/Tooltip"), require("../Typography"), require("./ToolbarDropdown"));
7
7
  } else {
8
8
  var mod = {
9
9
  exports: {}
10
10
  };
11
- factory(mod.exports, global.react, global.cva, global.ToolbarContext, global.utils, global.Icon, global.Tooltip, global.Typography);
11
+ factory(mod.exports, global.react, global.cva, global.ToolbarContext, global.utils, global.Icon, global.Tooltip, global.Typography, global.ToolbarDropdown);
12
12
  global.Toolbar = mod.exports;
13
13
  }
14
- })(typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : this, function (_exports, _react, _cva, _ToolbarContext, _utils, _Icon, _Tooltip, _Typography) {
14
+ })(typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : this, function (_exports, _react, _cva, _ToolbarContext, _utils, _Icon, _Tooltip, _Typography, _ToolbarDropdown) {
15
15
  "use strict";
16
16
 
17
17
  Object.defineProperty(_exports, "__esModule", {
18
18
  value: true
19
19
  });
20
20
  _exports.Toolbar = void 0;
21
- _react = _interopRequireDefault(_react);
22
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
21
+ _react = _interopRequireWildcard(_react);
22
+ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
23
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { "default": e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n["default"] = e, t && t.set(e, n), n; }
23
24
  function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
24
25
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
25
26
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
@@ -136,7 +137,13 @@
136
137
  variant: variant
137
138
  });
138
139
  }
139
- // For now, only simple actions are supported
140
+ if (action.type === 'dropdown') {
141
+ return /*#__PURE__*/_react["default"].createElement(_ToolbarDropdown.ToolbarDropdown, {
142
+ key: action.id,
143
+ action: action,
144
+ variant: variant
145
+ });
146
+ }
140
147
  return null;
141
148
  }));
142
149
  };
@@ -163,8 +170,9 @@
163
170
  "aria-label": "Formatting toolbar"
164
171
  }, filteredConfig.map(function (item, index) {
165
172
  if (item.type === 'group') {
166
- return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement(ToolbarGroup, {
167
- key: item.id,
173
+ return /*#__PURE__*/_react["default"].createElement(_react.Fragment, {
174
+ key: item.id
175
+ }, /*#__PURE__*/_react["default"].createElement(ToolbarGroup, {
168
176
  group: item,
169
177
  variant: variant
170
178
  }), filteredConfig.length > 1 && index < filteredConfig.length - 1 && /*#__PURE__*/_react["default"].createElement(ToolbarSeparator, null));
@@ -0,0 +1,199 @@
1
+ // This file is generated by a script. Do not edit this file directly.
2
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
3
+ (function (global, factory) {
4
+ if (typeof define === "function" && define.amd) {
5
+ define(["exports", "react", "cva", "../../common/utils", "../Icon", "./ToolbarContext"], factory);
6
+ } else if (typeof exports !== "undefined") {
7
+ factory(exports, require("react"), require("cva"), require("../../common/utils"), require("../Icon"), require("./ToolbarContext"));
8
+ } else {
9
+ var mod = {
10
+ exports: {}
11
+ };
12
+ factory(mod.exports, global.react, global.cva, global.utils, global.Icon, global.ToolbarContext);
13
+ global.ToolbarDropdown = mod.exports;
14
+ }
15
+ })(typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : this, function (_exports, _react, _cva, _utils, _Icon, _ToolbarContext) {
16
+ "use strict";
17
+
18
+ Object.defineProperty(_exports, "__esModule", {
19
+ value: true
20
+ });
21
+ _exports.ToolbarDropdown = void 0;
22
+ _react = _interopRequireWildcard(_react);
23
+ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
24
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { "default": e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n["default"] = e, t && t.set(e, n), n; }
25
+ function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
26
+ 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."); }
27
+ 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; } }
28
+ 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; }
29
+ 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; } }
30
+ function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
31
+ var buttonVariants = (0, _cva.cva)({
32
+ base: (0, _utils.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'),
33
+ variants: {
34
+ variant: {
35
+ highlight: 'cop-bg-white',
36
+ sticky: 'cop-bg-gray-100'
37
+ },
38
+ isOpen: {
39
+ "true": '!cop-bg-gray-200',
40
+ "false": ''
41
+ }
42
+ },
43
+ defaultVariants: {
44
+ variant: 'highlight',
45
+ isOpen: false
46
+ }
47
+ });
48
+ var iconStyles = (0, _utils.cn)('cop-flex cop-items-center cop-justify-center cop-h-4 cop-w-4 cop-text-gray-700');
49
+ var dropdownMenuStyles = (0, _utils.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');
50
+ var dropdownOptionStyles = (0, _utils.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');
51
+ var dropdownOptionFocusedStyles = '!cop-bg-gray-100';
52
+ var dropdownOptionIconStyles = (0, _utils.cn)('cop-h-4 cop-w-4 cop-text-gray-700');
53
+ var dropdownOptionLabelStyles = (0, _utils.cn)('cop-text-base');
54
+ var ToolbarDropdown = _exports.ToolbarDropdown = function ToolbarDropdown(_ref) {
55
+ var _ref2;
56
+ var action = _ref.action,
57
+ variant = _ref.variant;
58
+ var _useToolbar = (0, _ToolbarContext.useToolbar)(),
59
+ onAction = _useToolbar.onAction;
60
+ var _useState = (0, _react.useState)(null),
61
+ _useState2 = _slicedToArray(_useState, 2),
62
+ selectedOption = _useState2[0],
63
+ setSelectedOption = _useState2[1];
64
+ var _useState3 = (0, _react.useState)(false),
65
+ _useState4 = _slicedToArray(_useState3, 2),
66
+ isOpen = _useState4[0],
67
+ setIsOpen = _useState4[1];
68
+ var _useState5 = (0, _react.useState)(-1),
69
+ _useState6 = _slicedToArray(_useState5, 2),
70
+ focusedIndex = _useState6[0],
71
+ setFocusedIndex = _useState6[1];
72
+ var containerRef = (0, _react.useRef)(null);
73
+ var menuRef = (0, _react.useRef)(null);
74
+ var options = action.options;
75
+ var displayOption = (_ref2 = selectedOption !== null && selectedOption !== void 0 ? selectedOption : options[0]) !== null && _ref2 !== void 0 ? _ref2 : null;
76
+
77
+ // Close on outside click
78
+ (0, _react.useEffect)(function () {
79
+ if (!isOpen) return;
80
+ var handleClickOutside = function handleClickOutside(event) {
81
+ if (containerRef.current && !containerRef.current.contains(event.target)) {
82
+ setIsOpen(false);
83
+ }
84
+ };
85
+ document.addEventListener('mousedown', handleClickOutside);
86
+ return function () {
87
+ return document.removeEventListener('mousedown', handleClickOutside);
88
+ };
89
+ }, [isOpen]);
90
+
91
+ // Focus menu and reset index when opening/closing
92
+ (0, _react.useEffect)(function () {
93
+ if (isOpen) {
94
+ var _menuRef$current;
95
+ setFocusedIndex(0);
96
+ (_menuRef$current = menuRef.current) === null || _menuRef$current === void 0 || _menuRef$current.focus();
97
+ } else {
98
+ setFocusedIndex(-1);
99
+ }
100
+ }, [isOpen]);
101
+ var handleSelect = function handleSelect(option) {
102
+ setSelectedOption(option);
103
+ onAction({
104
+ id: action.id,
105
+ action: action.action,
106
+ metadata: {
107
+ value: option.value
108
+ }
109
+ });
110
+ setIsOpen(false);
111
+ };
112
+ var handleKeyDown = (0, _react.useCallback)(function (e) {
113
+ switch (e.key) {
114
+ case 'ArrowDown':
115
+ {
116
+ e.preventDefault();
117
+ setFocusedIndex(function (prev) {
118
+ return prev < options.length - 1 ? prev + 1 : 0;
119
+ });
120
+ break;
121
+ }
122
+ case 'ArrowUp':
123
+ {
124
+ e.preventDefault();
125
+ setFocusedIndex(function (prev) {
126
+ return prev > 0 ? prev - 1 : options.length - 1;
127
+ });
128
+ break;
129
+ }
130
+ case 'Enter':
131
+ case ' ':
132
+ {
133
+ e.preventDefault();
134
+ var focusedOption = options[focusedIndex];
135
+ if (focusedOption) {
136
+ handleSelect(focusedOption);
137
+ }
138
+ break;
139
+ }
140
+ case 'Escape':
141
+ {
142
+ e.preventDefault();
143
+ setIsOpen(false);
144
+ break;
145
+ }
146
+ default:
147
+ break;
148
+ }
149
+ }, [options, focusedIndex]);
150
+ return /*#__PURE__*/_react["default"].createElement("div", {
151
+ ref: containerRef,
152
+ className: "cop-relative"
153
+ }, /*#__PURE__*/_react["default"].createElement("button", {
154
+ type: "button",
155
+ className: (0, _utils.cn)(buttonVariants({
156
+ variant: variant,
157
+ isOpen: isOpen
158
+ })),
159
+ onClick: function onClick() {
160
+ return setIsOpen(!isOpen);
161
+ },
162
+ "aria-label": action.label,
163
+ "aria-expanded": isOpen,
164
+ "aria-haspopup": "listbox"
165
+ }, displayOption !== null && displayOption !== void 0 && displayOption.icon ? /*#__PURE__*/_react["default"].createElement(_Icon.Icon, {
166
+ className: iconStyles,
167
+ icon: displayOption.icon
168
+ }) : /*#__PURE__*/_react["default"].createElement("span", {
169
+ className: "cop-text-xs cop-text-gray-700"
170
+ }, displayOption === null || displayOption === void 0 ? void 0 : displayOption.label), /*#__PURE__*/_react["default"].createElement(_Icon.Icon, {
171
+ className: "cop-h-[10px] cop-w-[10px] cop-text-gray-700",
172
+ icon: "ChevronDown"
173
+ })), isOpen && /*#__PURE__*/_react["default"].createElement("div", {
174
+ ref: menuRef,
175
+ className: dropdownMenuStyles,
176
+ role: "listbox",
177
+ "aria-label": action.label,
178
+ tabIndex: -1,
179
+ onKeyDown: handleKeyDown
180
+ }, options.map(function (option, index) {
181
+ return /*#__PURE__*/_react["default"].createElement("button", {
182
+ key: option.value,
183
+ type: "button",
184
+ className: (0, _utils.cn)(dropdownOptionStyles, focusedIndex === index && dropdownOptionFocusedStyles),
185
+ role: "option",
186
+ "aria-selected": (selectedOption === null || selectedOption === void 0 ? void 0 : selectedOption.value) === option.value,
187
+ tabIndex: focusedIndex === index ? 0 : -1,
188
+ onClick: function onClick() {
189
+ return handleSelect(option);
190
+ }
191
+ }, option.icon && /*#__PURE__*/_react["default"].createElement(_Icon.Icon, {
192
+ className: dropdownOptionIconStyles,
193
+ icon: option.icon
194
+ }), /*#__PURE__*/_react["default"].createElement("span", {
195
+ className: dropdownOptionLabelStyles
196
+ }, option.label));
197
+ })));
198
+ };
199
+ });
@@ -40,7 +40,8 @@
40
40
  variant: "body",
41
41
  tag: tag,
42
42
  leading: "normal",
43
- weight: "regular"
43
+ weight: "regular",
44
+ "data-typography": "body"
44
45
  }, children);
45
46
  }
46
47
  });
@@ -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;
@@ -32,6 +32,7 @@ export interface GroupConfig {
32
32
  id: string;
33
33
  type: 'group';
34
34
  label: string;
35
+ icon?: IconType;
35
36
  actions: ActionConfig[];
36
37
  }
37
38
  export type ActionConfig = SimpleActionConfig | DropdownActionConfig | GroupConfig;
@@ -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 to exclude this component from certain styles in the webapp */
57
- 'data-typography'?: 'heading';
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'?: "heading" | undefined;
13
+ 'data-typography'?: string | undefined;
14
14
  }) => import("react").JSX.Element;
15
15
  tags: string[];
16
16
  };