oneslash-design-system 2.14.0 → 2.14.2

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.
@@ -11,9 +11,9 @@ interface ButtonProps extends React.AriaAttributes {
11
11
  state: 'enabled' | 'hovered' | 'focused' | 'disabled' | 'selected';
12
12
  label: string;
13
13
  secondLabel?: string;
14
- /** A Lucide icon name, an icon component (only that icon is bundled) or an element */
14
+ /** A Lucide icon name, an icon component (only that icon is bundled) or an element (`<Plus />`, the form a Server Component can pass) */
15
15
  decoIcon?: IconSource;
16
- /** A Lucide icon name, an icon component (only that icon is bundled) or an element */
16
+ /** A Lucide icon name, an icon component (only that icon is bundled) or an element (`<Plus />`, the form a Server Component can pass) */
17
17
  actionIcon?: IconSource;
18
18
  onClickButton?: any;
19
19
  onClickActionIcon?: () => void;
@@ -5,8 +5,8 @@ type IconName = keyof typeof icons;
5
5
  interface IconProps {
6
6
  /** A Lucide icon name. Give this or `icon`. */
7
7
  name?: IconName;
8
- /** An icon component, e.g. `Plus` from `lucide-react`: only that icon is bundled. Wins over `name`. */
9
- icon?: IconComponent;
8
+ /** An icon component, e.g. `Plus` from `lucide-react`, or an element (`<Plus />`, the form a Server Component can pass): only that icon is bundled. Wins over `name`. */
9
+ icon?: IconComponent | React.ReactElement;
10
10
  size?: 'tiny' | 'small' | 'medium' | 'large' | number;
11
11
  color?: 'primary' | 'secondary' | 'disabled' | 'error' | 'warning' | 'success' | 'info' | 'accent' | 'inherit';
12
12
  strokeWidth?: number;
@@ -10,7 +10,9 @@ export type IconComponent = React.ComponentType<any>;
10
10
  * - a Lucide icon name (`"Plus"`). The icon set loads in its own chunk the first time a name is used.
11
11
  * - an icon component (`Plus` from `lucide-react`). Sized and stroked like a named icon, and only
12
12
  * that icon is bundled.
13
- * - an element (`<Logo />`). Rendered as given; the caller sizes it.
13
+ * - an element (`<Plus />`, `<Logo />`). The only form a Server Component can pass. An element
14
+ * whose classes set no size is sized like a named icon; one with a size class of its own
15
+ * (`w-*`, `h-*`, `size-*`) is rendered as given, so the caller's size wins.
14
16
  */
15
17
  export type IconSource = string | IconComponent | React.ReactElement;
16
18
  interface IconSlotProps {
@@ -1,12 +1,40 @@
1
1
  'use client';
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
2
13
  import React, { Suspense, lazy } from 'react';
3
14
  var NamedIcon = lazy(function () { return import('./namedIcon'); });
15
+ // A Tailwind class that sets a width or a height, with any variant or `!` in front
16
+ var SIZE_CLASS = /(^|[\s:!])(w|h|size)-/;
4
17
  export default function IconSlot(_a) {
5
- var icon = _a.icon, className = _a.className, _b = _a.strokeWidth, strokeWidth = _b === void 0 ? 2 : _b, size = _a.size, warnIfMissing = _a.warnIfMissing;
18
+ var _b;
19
+ var icon = _a.icon, className = _a.className, _c = _a.strokeWidth, strokeWidth = _c === void 0 ? 2 : _c, size = _a.size, warnIfMissing = _a.warnIfMissing;
6
20
  if (!icon)
7
21
  return null;
8
- if (React.isValidElement(icon))
9
- return icon;
22
+ if (React.isValidElement(icon)) {
23
+ var own = icon.props;
24
+ // The caller's own size wins: two size classes on one element would leave the result to CSS order
25
+ if (own.className && SIZE_CLASS.test(own.className))
26
+ return icon;
27
+ var merged = [own.className, className].filter(Boolean).join(' ') || undefined;
28
+ // A Lucide icon passed from a Server Component arrives already rendered, as an <svg> with
29
+ // Lucide's own classes and its default width and height. The size class overrides those
30
+ // attributes; a pixel size replaces them.
31
+ if (typeof icon.type === 'string') {
32
+ var box = size !== undefined && icon.type === 'svg' ? { width: size, height: size } : {};
33
+ return React.cloneElement(icon, __assign({ className: merged }, box));
34
+ }
35
+ // `strokeWidth` and `size` are props of an icon component, not attributes of a plain tag
36
+ return React.cloneElement(icon, __assign({ className: merged, strokeWidth: (_b = own.strokeWidth) !== null && _b !== void 0 ? _b : strokeWidth }, (size !== undefined && own.size === undefined ? { size: size } : {})));
37
+ }
10
38
  if (typeof icon === 'string') {
11
39
  return (
12
40
  // The empty box holds the icon's place until the icon set has loaded
@@ -163,12 +163,14 @@ export var AriaExpanded = {
163
163
  },
164
164
  };
165
165
  // An icon can be a component or an element instead of a name. A component is sized like a
166
- // named icon and only that icon is bundled; an element is rendered as given.
166
+ // named icon and only that icon is bundled. So is an element without a className (what a
167
+ // Server Component passes); an element with a className is rendered as given.
167
168
  export var IconComponents = {
168
169
  render: function () { return (<div style={{ display: "flex", gap: "16px", alignItems: "center" }}>
169
170
  <Button size="medium" type="primary" state="enabled" label="Component" decoIcon={Star} actionIcon={ChevronRight}/>
170
171
  <Button size="medium" type="secondary" state="enabled" label="By name" decoIcon="Star" actionIcon="ChevronRight"/>
171
172
  <Button size="medium" type="tertiary" state="enabled" label="Element" decoIcon={<span className="w-5 h-5 rounded-full bg-accent-main flex-shrink-0"/>}/>
173
+ <Button size="medium" type="tertiary" state="enabled" label="Icon element" decoIcon={<Star />} actionIcon={<ChevronRight />}/>
172
174
  </div>); },
173
175
  };
174
176
  // `href` renders a link with the button's look: next/link for a path, a plain <a> for another site
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "oneslash-design-system",
3
3
  "description": "A design system for the Oneslash projects",
4
- "version": "2.14.0",
4
+ "version": "2.14.2",
5
5
  "license": "MIT",
6
6
  "private": false,
7
7
  "main": "./dist/index.js",