@openwarelabs/ui 0.1.0 → 0.2.0

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 (40) hide show
  1. package/README.md +2 -2
  2. package/dist/components/Accordion/Accordion.d.cts +1 -1
  3. package/dist/components/Accordion/Accordion.d.ts +1 -1
  4. package/dist/components/Avatar/Avatar.d.cts +13 -2
  5. package/dist/components/Avatar/Avatar.d.ts +13 -2
  6. package/dist/components/Avatar/AvatarGroup.d.cts +7 -6
  7. package/dist/components/Avatar/AvatarGroup.d.ts +7 -6
  8. package/dist/components/CodeBlock/CodeBlock.d.cts +1 -1
  9. package/dist/components/CodeBlock/CodeBlock.d.ts +1 -1
  10. package/dist/components/FileDropZone/FileDropZone.d.cts +1 -1
  11. package/dist/components/FileDropZone/FileDropZone.d.ts +1 -1
  12. package/dist/components/FileTree/FileTree.d.cts +1 -1
  13. package/dist/components/FileTree/FileTree.d.ts +1 -1
  14. package/dist/components/Progress/Progress.d.cts +1 -1
  15. package/dist/components/Progress/Progress.d.ts +1 -1
  16. package/dist/components/Stat/Stat.d.cts +1 -1
  17. package/dist/components/Stat/Stat.d.ts +1 -1
  18. package/dist/components/Steps/Steps.d.cts +2 -2
  19. package/dist/components/Steps/Steps.d.ts +2 -2
  20. package/dist/components/Table/Table.d.cts +6 -1
  21. package/dist/components/Table/Table.d.ts +6 -1
  22. package/dist/components/Tabs/Tabs.d.cts +1 -1
  23. package/dist/components/Tabs/Tabs.d.ts +1 -1
  24. package/dist/components/Tooltip/Tooltip.d.cts +3 -3
  25. package/dist/components/Tooltip/Tooltip.d.ts +3 -3
  26. package/dist/components.css +58 -16
  27. package/dist/hooks/useFloating.d.cts +2 -2
  28. package/dist/hooks/useFloating.d.ts +2 -2
  29. package/dist/index.cjs +46 -7
  30. package/dist/index.cjs.map +3 -3
  31. package/dist/index.d.cts +1 -1
  32. package/dist/index.d.ts +1 -1
  33. package/dist/index.js +46 -7
  34. package/dist/index.js.map +3 -3
  35. package/dist/openware-ui.iife.js +5 -5
  36. package/dist/styles.css +61 -16
  37. package/dist/tailwind.css +1 -0
  38. package/dist/tokens.css +3 -0
  39. package/dist/tokens.json +1110 -191
  40. package/package.json +2 -2
@@ -1,5 +1,5 @@
1
1
  import { type CSSProperties, type RefObject } from "react";
2
- export type Placement = "bottom-start" | "bottom-end" | "bottom" | "top-start" | "top-end" | "top";
2
+ export type Placement = "bottom-start" | "bottom-end" | "bottom" | "top-start" | "top-end" | "top" | "left" | "right";
3
3
  interface Options {
4
4
  open: boolean;
5
5
  anchorRef: RefObject<HTMLElement | null>;
@@ -14,7 +14,7 @@ interface Options {
14
14
  }
15
15
  /**
16
16
  * Positions a floating element (a popover, a listbox) against its anchor with fixed coordinates, flips it above
17
- * or below when there's no room, keeps it on screen, and follows the anchor when the page scrolls or resizes.
17
+ * or below (or, for "left" and "right", to the other side) when there's no room, keeps it on screen, and follows the anchor when the page scrolls or resizes.
18
18
  * It also puts the element in the browser's top layer (popover="manual"), so dialogs and overflow can't clip it.
19
19
  * Pass the element's `mounted` from usePresence as `open`, so it stays placed while it animates out.
20
20
  */
package/dist/index.cjs CHANGED
@@ -1172,6 +1172,25 @@ function useFloating({
1172
1172
  const rect = anchor.getBoundingClientRect();
1173
1173
  const width = Math.max(floating.offsetWidth, matchWidth ? rect.width : 0);
1174
1174
  const height = floating.scrollHeight;
1175
+ if (placement === "left" || placement === "right") {
1176
+ const roomLeft = rect.left - offset - margin;
1177
+ const roomRight = window.innerWidth - rect.right - offset - margin;
1178
+ const onLeft = placement === "left" ? width <= roomLeft || roomLeft > roomRight : width > roomRight && roomLeft > roomRight;
1179
+ const top2 = Math.min(Math.max(margin, rect.top + rect.height / 2 - height / 2), window.innerHeight - height - margin);
1180
+ floating.dataset.side = onLeft ? "left" : "right";
1181
+ setStyle({
1182
+ position: "fixed",
1183
+ inset: "auto",
1184
+ margin: 0,
1185
+ left: onLeft ? "auto" : rect.right + offset,
1186
+ right: onLeft ? window.innerWidth - rect.left + offset : "auto",
1187
+ top: top2,
1188
+ bottom: "auto",
1189
+ maxHeight: Math.max(120, Math.min(maxHeight, window.innerHeight - 2 * margin)),
1190
+ ["--ow-floating-origin"]: `${onLeft ? "right" : "left"} center`
1191
+ });
1192
+ return;
1193
+ }
1175
1194
  const below = window.innerHeight - rect.bottom - offset - margin;
1176
1195
  const above = rect.top - offset - margin;
1177
1196
  const wantsTop = placement.startsWith("top");
@@ -3643,7 +3662,7 @@ function Steps({ items: items2, current = 0, orientation = "vertical", title, la
3643
3662
  ] }),
3644
3663
  item.description && (orientation === "horizontal" || status !== "done") ? /* @__PURE__ */ (0, import_jsx_runtime38.jsx)("span", { className: "ow-steps__description", children: item.description }) : null
3645
3664
  ] }),
3646
- item.action && status !== "done" && orientation === "vertical" ? /* @__PURE__ */ (0, import_jsx_runtime38.jsx)("span", { className: "ow-steps__action", children: item.action }) : null
3665
+ item.action && status === "current" && orientation === "vertical" ? /* @__PURE__ */ (0, import_jsx_runtime38.jsx)("span", { className: "ow-steps__action", children: item.action }) : null
3647
3666
  ]
3648
3667
  },
3649
3668
  index
@@ -3726,6 +3745,7 @@ function Table({
3726
3745
  selectedKeys,
3727
3746
  defaultSelectedKeys = [],
3728
3747
  onSelectionChange,
3748
+ rowLabel,
3729
3749
  emptyContent = "Nothing here yet.",
3730
3750
  density = "comfortable",
3731
3751
  stickyHeader = false,
@@ -3735,6 +3755,11 @@ function Table({
3735
3755
  const [currentSort, setSort] = useControllableState(sort, defaultSort, onSortChange);
3736
3756
  const [selected, setSelected] = useControllableState(selectedKeys, defaultSelectedKeys, onSelectionChange);
3737
3757
  const keyOf = (row) => typeof rowKey === "function" ? rowKey(row) : row[rowKey];
3758
+ const labelOf = (row, index) => {
3759
+ if (rowLabel) return rowLabel(row);
3760
+ const first = columns[0] ? row[columns[0].key] : void 0;
3761
+ return typeof first === "string" || typeof first === "number" ? String(first) : `row ${index + 1}`;
3762
+ };
3738
3763
  const field = (row, key) => row[key];
3739
3764
  const sorted = (0, import_react41.useMemo)(() => {
3740
3765
  if (!currentSort || manualSort) return rows;
@@ -3791,7 +3816,7 @@ function Table({
3791
3816
  );
3792
3817
  })
3793
3818
  ] }) }),
3794
- /* @__PURE__ */ (0, import_jsx_runtime40.jsx)("tbody", { children: sorted.length === 0 ? /* @__PURE__ */ (0, import_jsx_runtime40.jsx)("tr", { children: /* @__PURE__ */ (0, import_jsx_runtime40.jsx)("td", { className: "ow-table__empty", colSpan: columns.length + (selectable ? 1 : 0), children: emptyContent }) }) : sorted.map((row) => {
3819
+ /* @__PURE__ */ (0, import_jsx_runtime40.jsx)("tbody", { children: sorted.length === 0 ? /* @__PURE__ */ (0, import_jsx_runtime40.jsx)("tr", { children: /* @__PURE__ */ (0, import_jsx_runtime40.jsx)("td", { className: "ow-table__empty", colSpan: columns.length + (selectable ? 1 : 0), children: emptyContent }) }) : sorted.map((row, index) => {
3795
3820
  const key = keyOf(row);
3796
3821
  const isSelected = selected.includes(key);
3797
3822
  return /* @__PURE__ */ (0, import_jsx_runtime40.jsxs)("tr", { className: cx(isSelected && "ow-table__row--selected"), children: [
@@ -3799,7 +3824,7 @@ function Table({
3799
3824
  Checkbox,
3800
3825
  {
3801
3826
  size: "sm",
3802
- "aria-label": "Select row",
3827
+ "aria-label": `Select ${labelOf(row, index)}`,
3803
3828
  checked: isSelected,
3804
3829
  onChange: (event) => setSelected(
3805
3830
  event.target.checked ? [...selected, key] : selected.filter((k) => k !== key)
@@ -4029,16 +4054,25 @@ function ColorSwatch({ color, name, value, size = "md", shape = "square", classN
4029
4054
  // src/components/Avatar/Avatar.tsx
4030
4055
  var import_react43 = require("react");
4031
4056
  var import_jsx_runtime45 = require("react/jsx-runtime");
4057
+ var namedSizes = { sm: 24, md: 28, lg: 36, xl: 48 };
4058
+ function avatarSize(size) {
4059
+ if (typeof size === "number") {
4060
+ return { className: "ow-avatar--custom", style: { "--ow-avatar-size": `${size}px` }, pixels: size };
4061
+ }
4062
+ return { className: `ow-avatar--${size}`, pixels: namedSizes[size] };
4063
+ }
4032
4064
  function Avatar({ name, src, size = "md", label, className }) {
4033
4065
  const initials = getInitials(name);
4034
4066
  const [failedImage, setFailedImage] = (0, import_react43.useState)();
4035
4067
  const showImage = src && src !== failedImage;
4068
+ const sizing = avatarSize(size);
4036
4069
  return /* @__PURE__ */ (0, import_jsx_runtime45.jsx)(
4037
4070
  "span",
4038
4071
  {
4039
- className: cx("ow-avatar", `ow-avatar--${size}`, !initials && !showImage && "ow-avatar--empty", className),
4072
+ className: cx("ow-avatar", sizing.className, !initials && !showImage && "ow-avatar--empty", className),
4073
+ style: sizing.style,
4040
4074
  ...label ? { role: "img", "aria-label": label } : { "aria-hidden": true },
4041
- children: showImage ? /* @__PURE__ */ (0, import_jsx_runtime45.jsx)("img", { src, alt: "", className: "ow-avatar__image", onError: () => setFailedImage(src) }) : initials || /* @__PURE__ */ (0, import_jsx_runtime45.jsx)(UserIcon, { size: size === "sm" ? 13 : size === "lg" ? 18 : 15 })
4075
+ children: showImage ? /* @__PURE__ */ (0, import_jsx_runtime45.jsx)("img", { src, alt: "", className: "ow-avatar__image", onError: () => setFailedImage(src) }) : initials || /* @__PURE__ */ (0, import_jsx_runtime45.jsx)(UserIcon, { size: Math.round(sizing.pixels * 0.52) })
4042
4076
  }
4043
4077
  );
4044
4078
  }
@@ -4048,11 +4082,12 @@ var import_react44 = require("react");
4048
4082
  var import_jsx_runtime46 = require("react/jsx-runtime");
4049
4083
  function AvatarGroup({ children, max = 4, size = "md", label, className }) {
4050
4084
  const avatars = import_react44.Children.toArray(children).filter(import_react44.isValidElement);
4085
+ const sizing = avatarSize(size);
4051
4086
  const shown = avatars.slice(0, max);
4052
4087
  const hidden = avatars.length - shown.length;
4053
4088
  return /* @__PURE__ */ (0, import_jsx_runtime46.jsxs)("div", { role: "group", "aria-label": label, className: cx("ow-avatar-group", className), children: [
4054
4089
  shown.map((avatar) => (0, import_react44.cloneElement)(avatar, { size })),
4055
- hidden > 0 ? /* @__PURE__ */ (0, import_jsx_runtime46.jsxs)("span", { className: cx("ow-avatar", `ow-avatar--${size}`, "ow-avatar--count"), children: [
4090
+ hidden > 0 ? /* @__PURE__ */ (0, import_jsx_runtime46.jsxs)("span", { className: cx("ow-avatar", sizing.className, "ow-avatar--count"), style: sizing.style, children: [
4056
4091
  /* @__PURE__ */ (0, import_jsx_runtime46.jsxs)("span", { "aria-hidden": "true", children: [
4057
4092
  "+",
4058
4093
  hidden
@@ -4065,8 +4100,12 @@ function AvatarGroup({ children, max = 4, size = "md", label, className }) {
4065
4100
  ] }) : null
4066
4101
  ] });
4067
4102
  }
4103
+ function userSize(size) {
4104
+ if (typeof size !== "number") return `ow-user--${size}`;
4105
+ return size >= 48 ? "ow-user--xl" : size >= 36 ? "ow-user--lg" : size >= 28 ? "ow-user--md" : "ow-user--sm";
4106
+ }
4068
4107
  function User({ name, description, src, size = "md", className }) {
4069
- return /* @__PURE__ */ (0, import_jsx_runtime46.jsxs)("div", { className: cx("ow-user", `ow-user--${size}`, className), children: [
4108
+ return /* @__PURE__ */ (0, import_jsx_runtime46.jsxs)("div", { className: cx("ow-user", userSize(size), className), children: [
4070
4109
  /* @__PURE__ */ (0, import_jsx_runtime46.jsx)(Avatar, { name, src, size }),
4071
4110
  /* @__PURE__ */ (0, import_jsx_runtime46.jsxs)("div", { className: "ow-user__text", children: [
4072
4111
  /* @__PURE__ */ (0, import_jsx_runtime46.jsx)("span", { className: "ow-user__name", children: name }),