@solexllc/usx-react 0.12.0 → 1.0.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 (97) hide show
  1. package/README.md +15 -0
  2. package/dist/{Popover-BzDCTuQM.cjs → Popover-Bg4-2-cU.cjs} +3 -0
  3. package/dist/{Popover-LToVWsWc.js → Popover-CqHczzNE.js} +3 -0
  4. package/dist/chat.cjs +7 -2
  5. package/dist/chat.js +7 -2
  6. package/dist/index.cjs +83 -56
  7. package/dist/index.js +86 -59
  8. package/package.json +4 -4
  9. package/src/components/accordion/Accordion.tsx +9 -57
  10. package/src/components/accordion/accordion.django.html +10 -20
  11. package/src/components/accordion/config.json +8 -2
  12. package/src/components/accordion-item/AccordionItem.tsx +54 -0
  13. package/src/components/accordion-item/accordion-item.django.html +19 -0
  14. package/src/components/accordion-item/accordion-item.html +8 -0
  15. package/src/components/accordion-item/config.json +55 -0
  16. package/src/components/alert/alert.django-snapshot.html +4 -4
  17. package/src/components/avatar/avatar.django-snapshot.html +6 -2
  18. package/src/components/avatar/avatar.react-snapshot.html +6 -3
  19. package/src/components/avatar/config.json +4 -2
  20. package/src/components/avatar-group/avatar-group.django-snapshot.html +176 -176
  21. package/src/components/avatar-group/avatar-group.react-snapshot.html +198 -167
  22. package/src/components/avatar-group/config.json +12 -6
  23. package/src/components/banner/banner.django-snapshot.html +2 -2
  24. package/src/components/button/Button.tsx +3 -0
  25. package/src/components/button/button.django-snapshot.html +64 -0
  26. package/src/components/button/button.django.html +2 -0
  27. package/src/components/button/button.react-snapshot.html +64 -0
  28. package/src/components/button/config.json +6 -1
  29. package/src/components/card/card.django-snapshot.html +43 -0
  30. package/src/components/card/card.react-snapshot.html +36 -0
  31. package/src/components/chat/chat.django-snapshot.html +90 -26
  32. package/src/components/chat/chat.html +10 -10
  33. package/src/components/chat/chat.react-snapshot.html +49 -49
  34. package/src/components/chat-composer/ChatComposer.tsx +3 -0
  35. package/src/components/chat-composer/chat-composer.django-snapshot.html +10 -10
  36. package/src/components/chat-composer/chat-composer.django.html +2 -2
  37. package/src/components/chat-composer/chat-composer.html +10 -10
  38. package/src/components/chat-composer/chat-composer.react-snapshot.html +10 -10
  39. package/src/components/chat-composer/chat-formatting.django.html +8 -8
  40. package/src/components/chat-window/ChatWindow.tsx +3 -1
  41. package/src/components/chat-window/chat-window.django-snapshot.html +7 -5
  42. package/src/components/chat-window/chat-window.django.html +3 -3
  43. package/src/components/chat-window/chat-window.html +1 -1
  44. package/src/components/chat-window/chat-window.react-snapshot.html +7 -7
  45. package/src/components/checkbox/checkbox.django-snapshot.html +2 -2
  46. package/src/components/data-table/data-table.django-snapshot.html +4 -5
  47. package/src/components/data-table/data-table.react-snapshot.html +4 -4
  48. package/src/components/drawer/drawer.django-snapshot.html +53 -30
  49. package/src/components/error-page/error-page.django-snapshot.html +20 -7
  50. package/src/components/fieldset/fieldset.django-snapshot.html +1 -6
  51. package/src/components/form-group/form-group.django-snapshot.html +0 -2
  52. package/src/components/header/header.django-snapshot.html +3 -3
  53. package/src/components/header/header.html +1 -1
  54. package/src/components/header/header.react-snapshot.html +3 -3
  55. package/src/components/identifier/config.json +4 -2
  56. package/src/components/identifier/identifier.django-snapshot.html +13 -16
  57. package/src/components/identifier/identifier.react-snapshot.html +13 -15
  58. package/src/components/image/image.django-snapshot.html +6 -6
  59. package/src/components/layout/layout.django-snapshot.html +2 -0
  60. package/src/components/modal/Modal.tsx +4 -3
  61. package/src/components/modal/config.json +3 -2
  62. package/src/components/modal/modal.django-snapshot.html +70 -14
  63. package/src/components/modal/modal.django.html +7 -9
  64. package/src/components/modal/modal.html +4 -4
  65. package/src/components/modal/modal.react-snapshot.html +64 -4
  66. package/src/components/page/Page.tsx +10 -7
  67. package/src/components/page/page.django-snapshot.html +5 -8
  68. package/src/components/page/page.django.html +2 -2
  69. package/src/components/page/page.html +1 -2
  70. package/src/components/page/page.react-snapshot.html +5 -8
  71. package/src/components/pagination/navigation/PaginationNavigation.tsx +2 -0
  72. package/src/components/pagination/navigation/pagination-navigation.django.html +2 -0
  73. package/src/components/pagination/pagination.django-snapshot.html +62 -0
  74. package/src/components/pagination/pagination.django.html +3 -1
  75. package/src/components/pagination/pagination.html +46 -0
  76. package/src/components/pagination/pagination.react-snapshot.html +48 -0
  77. package/src/components/pagination/summary/PaginationSummary.tsx +1 -1
  78. package/src/components/pagination/summary/pagination-summary.django.html +1 -1
  79. package/src/components/popover/Popover.tsx +1 -0
  80. package/src/components/popover/popover.django-snapshot.html +37 -1
  81. package/src/components/popover/popover.django.html +1 -1
  82. package/src/components/popover/popover.react-snapshot.html +30 -3
  83. package/src/components/section/Section.tsx +3 -1
  84. package/src/components/site-alert/site-alert.django-snapshot.html +8 -8
  85. package/src/components/swap/Swap.tsx +35 -3
  86. package/src/components/swap/config.json +28 -1
  87. package/src/components/swap/swap.django-snapshot.html +29 -7
  88. package/src/components/swap/swap.django.html +15 -1
  89. package/src/components/swap/swap.react-snapshot.html +34 -4
  90. package/src/components/theme-picker/ThemePicker.tsx +48 -42
  91. package/src/components/theme-picker/config.json +27 -29
  92. package/src/components/theme-picker/theme-picker-select.django.html +1 -1
  93. package/src/components/theme-picker/theme-picker.django-snapshot.html +283 -78
  94. package/src/components/theme-picker/theme-picker.django.html +24 -11
  95. package/src/components/theme-picker/theme-picker.html +155 -54
  96. package/src/components/theme-picker/theme-picker.react-snapshot.html +265 -67
  97. package/src/index.js +1 -0
package/dist/index.js CHANGED
@@ -1,11 +1,12 @@
1
- import { jsx, jsxs, Fragment } from "react/jsx-runtime";
2
- import { C as ClassNames, A as Avatar, B as Button, g as getAssetUrl, I as Icon, a as Image, T as Tag, b as ButtonGroup, F as FormGroup, L as Label, H as Hint, E as ErrorMessage, c as TextArea, R as Required, d as Tooltip, S as Summary, e as TagGroup, f as Link, h as Callout, i as Alert, j as Clickable } from "./Popover-LToVWsWc.js";
3
- import { k, P, l } from "./Popover-LToVWsWc.js";
1
+ import { jsxs, Fragment, jsx } from "react/jsx-runtime";
2
+ import { C as ClassNames, A as Avatar, B as Button, g as getAssetUrl, I as Icon, a as Image, T as Tag, b as ButtonGroup, F as FormGroup, L as Label, H as Hint, E as ErrorMessage, c as TextArea, R as Required, d as Tooltip, S as Summary, e as TagGroup, f as Link, h as Callout, i as Alert, j as Clickable, P as Popover } from "./Popover-CqHczzNE.js";
3
+ import { k, l } from "./Popover-CqHczzNE.js";
4
4
  import React, { createContext, useContext, useId, useRef, useState, createElement } from "react";
5
5
  function AccordionItem({
6
6
  title,
7
7
  id,
8
8
  content,
9
+ children,
9
10
  expanded = false,
10
11
  headingClassName,
11
12
  contentClassName,
@@ -13,11 +14,7 @@ function AccordionItem({
13
14
  handleToggle
14
15
  }) {
15
16
  const headingClasses = ClassNames("usa-accordion__heading", headingClassName);
16
- const contentClasses = ClassNames(
17
- "usa-accordion__content",
18
- "usa-prose",
19
- contentClassName
20
- );
17
+ const contentClasses = ClassNames("usa-accordion__content", "usa-prose", contentClassName);
21
18
  const Heading = headingAs;
22
19
  return /* @__PURE__ */ jsxs(Fragment, { children: [
23
20
  /* @__PURE__ */ jsx(Heading, { id: `${id}-heading`, className: headingClasses, children: /* @__PURE__ */ jsx(
@@ -38,7 +35,7 @@ function AccordionItem({
38
35
  "aria-labelledby": `${id}-heading`,
39
36
  className: contentClasses,
40
37
  hidden: !expanded,
41
- children: content
38
+ children: children ?? content
42
39
  }
43
40
  )
44
41
  ] });
@@ -71,15 +68,16 @@ function Accordion({
71
68
  "data-allow-multiple": multiselectable ? true : void 0,
72
69
  ...props2,
73
70
  ...extraAttributes,
74
- children: items.map((item) => /* @__PURE__ */ jsx(
71
+ children: items.map((item, index) => /* @__PURE__ */ jsx(
75
72
  AccordionItem,
76
73
  {
77
74
  ...item,
75
+ id: item.id || `${id ?? ""}-${index}`,
78
76
  headingAs,
79
77
  headingClassName,
80
78
  contentClassName
81
79
  },
82
- item.id
80
+ item.id || `${id ?? ""}-${index}`
83
81
  ))
84
82
  }
85
83
  );
@@ -1455,6 +1453,7 @@ function TableCell({
1455
1453
  function getPageItems(currentPage, totalPages) {
1456
1454
  const page = (p) => ({ type: "page", page: p });
1457
1455
  const ellipsis = (key) => ({ type: "ellipsis", key });
1456
+ if (totalPages <= 1) return [];
1458
1457
  if (totalPages <= 7) {
1459
1458
  return Array.from({ length: totalPages }, (_, i) => page(i + 1));
1460
1459
  }
@@ -1512,6 +1511,7 @@ function PaginationNavigation({
1512
1511
  onPageChange
1513
1512
  }) {
1514
1513
  const unbounded = totalPages === void 0 || totalPages === null;
1514
+ if (!unbounded && totalPages <= 1) return null;
1515
1515
  const items = unbounded ? getUnboundedPageItems(currentPage) : getPageItems(currentPage, totalPages);
1516
1516
  const isFirstPage = currentPage === 1;
1517
1517
  const isLastPage = !unbounded && currentPage === totalPages;
@@ -1736,7 +1736,7 @@ function PaginationSummary({
1736
1736
  itemLabel = "items",
1737
1737
  className = ""
1738
1738
  }) {
1739
- const firstItem = (currentPage - 1) * pageSize + 1;
1739
+ const firstItem = totalItems === 0 ? 0 : (currentPage - 1) * pageSize + 1;
1740
1740
  const lastItem = Math.min(currentPage * pageSize, totalItems);
1741
1741
  const classes = ClassNames(
1742
1742
  "usa-label",
@@ -2261,7 +2261,7 @@ function Drawer({
2261
2261
  }
2262
2262
  function Page({
2263
2263
  id = void 0,
2264
- title = "Page title",
2264
+ title,
2265
2265
  titleId = void 0,
2266
2266
  eyebrow = null,
2267
2267
  subtitle = void 0,
@@ -2278,7 +2278,8 @@ function Page({
2278
2278
  const hasSummary = Boolean(subtitle || description || (tagProps == null ? void 0 : tagProps.length));
2279
2279
  const classes = ClassNames("usx-page", className);
2280
2280
  const pageContent = children || content;
2281
- const labelledBy = ariaLabelledby || titleId || void 0;
2281
+ const hasTitle = Boolean(title) && typeof title !== "boolean" || title === 0;
2282
+ const labelledBy = ariaLabelledby || (hasTitle ? titleId : void 0);
2282
2283
  return /* @__PURE__ */ jsxs(
2283
2284
  Element,
2284
2285
  {
@@ -2288,8 +2289,8 @@ function Page({
2288
2289
  "aria-labelledby": labelledBy,
2289
2290
  ...props2,
2290
2291
  children: [
2291
- /* @__PURE__ */ jsxs("h1", { id: titleId, className: "usx-page__title", children: [
2292
- eyebrow ? /* @__PURE__ */ jsx("span", { className: "usx-eyebrow", children: eyebrow }) : null,
2292
+ hasTitle && /* @__PURE__ */ jsxs("h1", { id: titleId, className: "usx-page__title", children: [
2293
+ eyebrow && typeof eyebrow !== "boolean" ? /* @__PURE__ */ jsx("span", { className: "usx-eyebrow", children: eyebrow }) : null,
2293
2294
  title
2294
2295
  ] }),
2295
2296
  hasSummary && /* @__PURE__ */ jsxs("div", { className: "usx-page__summary", children: [
@@ -3753,7 +3754,7 @@ function Modal({
3753
3754
  description,
3754
3755
  actionProps = [
3755
3756
  { children: "Continue", variant: "primary", extraAttributes: { "data-close-modal": true } },
3756
- { children: "Go back", variant: "unstyled", className: "padding-105 text-center", extraAttributes: { "data-close-modal": true } }
3757
+ { children: "Go back", variant: "unstyled", tighten: true, className: "text-center", extraAttributes: { "data-close-modal": true } }
3757
3758
  ],
3758
3759
  size = "default",
3759
3760
  forceAction = false,
@@ -3766,6 +3767,7 @@ function Modal({
3766
3767
  "usa-modal--lg": size === "lg",
3767
3768
  "usx-modal--lg-collapsed": size === "lg-collapsed"
3768
3769
  }, className);
3770
+ const hasChildren = children != null;
3769
3771
  return /* @__PURE__ */ jsx(
3770
3772
  "div",
3771
3773
  {
@@ -3779,7 +3781,7 @@ function Modal({
3779
3781
  children: /* @__PURE__ */ jsxs("div", { className: "usa-modal__content", children: [
3780
3782
  /* @__PURE__ */ jsxs("div", { className: "usa-modal__main", children: [
3781
3783
  /* @__PURE__ */ jsx("h2", { className: "usa-modal__heading", id: `${id}-heading`, children: heading }),
3782
- /* @__PURE__ */ jsx(Prose, { children: /* @__PURE__ */ jsx("p", { id: `${id}-description`, children: children ?? description }) }),
3784
+ /* @__PURE__ */ jsx(Prose, { id: hasChildren ? `${id}-description` : void 0, children: hasChildren ? /* @__PURE__ */ jsx(Fragment, { children }) : /* @__PURE__ */ jsx("p", { id: `${id}-description`, children: description }) }),
3783
3785
  /* @__PURE__ */ jsx("div", { className: "usa-modal__footer", children: /* @__PURE__ */ jsx(ButtonGroup, { buttonProps: actionProps }) })
3784
3786
  ] }),
3785
3787
  !forceAction && /* @__PURE__ */ jsx(
@@ -4122,6 +4124,10 @@ const Swap = ({
4122
4124
  children = null,
4123
4125
  className = "",
4124
4126
  variant = "default",
4127
+ as = "label",
4128
+ defaultPressed = false,
4129
+ ariaLabel,
4130
+ disabled = false,
4125
4131
  onContent = "ON",
4126
4132
  offContent = "OFF",
4127
4133
  includeInput = true,
@@ -4131,14 +4137,33 @@ const Swap = ({
4131
4137
  ...props2
4132
4138
  }) => {
4133
4139
  const variantClass = variant !== "default" ? `usx-swap--${variant}` : "";
4134
- const classes = ClassNames("usx-swap", variantClass, className);
4140
+ const classes = ClassNames(
4141
+ "usx-swap",
4142
+ variantClass,
4143
+ as === "button" && "usa-button usx-button usx-swap--button",
4144
+ className
4145
+ );
4135
4146
  const onClasses = ClassNames("usx-swap-on", onClassName);
4136
4147
  const offClasses = ClassNames("usx-swap-off", offClassName);
4137
4148
  const content = children || /* @__PURE__ */ jsxs(Fragment, { children: [
4138
- includeInput ? /* @__PURE__ */ jsx("input", { type: "checkbox", autoComplete: "off", ...inputProps }) : null,
4149
+ as === "label" && includeInput ? /* @__PURE__ */ jsx("input", { type: "checkbox", autoComplete: "off", ...inputProps }) : null,
4139
4150
  /* @__PURE__ */ jsx("span", { className: onClasses, children: onContent }),
4140
4151
  /* @__PURE__ */ jsx("span", { className: offClasses, children: offContent })
4141
4152
  ] });
4153
+ if (as === "button") {
4154
+ return /* @__PURE__ */ jsx(
4155
+ "button",
4156
+ {
4157
+ type: "button",
4158
+ className: classes,
4159
+ "aria-pressed": defaultPressed,
4160
+ "aria-label": ariaLabel,
4161
+ disabled,
4162
+ ...props2,
4163
+ children: content
4164
+ }
4165
+ );
4166
+ }
4142
4167
  return /* @__PURE__ */ jsx("label", { className: classes, ...props2, children: content });
4143
4168
  };
4144
4169
  function Switch({ className, labelClassName, color, ...props2 }) {
@@ -4233,34 +4258,24 @@ function ThemePicker({
4233
4258
  label = "Theme",
4234
4259
  themes = [],
4235
4260
  variant = "default",
4261
+ popoverAlign = "start",
4236
4262
  value,
4237
4263
  defaultValue,
4238
- onChange,
4239
4264
  className = "",
4240
4265
  extraAttributes
4241
4266
  }) {
4242
- var _a, _b, _c, _d, _e, _f;
4243
- const selectId = id || "theme-picker";
4244
- const [localValue, setLocalValue] = React.useState(defaultValue ?? ((_a = themes[0]) == null ? void 0 : _a.value) ?? "");
4245
- const selectedValue = value ?? localValue;
4246
- const selectedLabel = ((_b = themes.find((option) => option.value === selectedValue)) == null ? void 0 : _b.label) ?? label;
4247
- const choose = (next) => {
4248
- if (value === void 0) setLocalValue(next);
4249
- onChange == null ? void 0 : onChange(next);
4250
- };
4251
- const select = (hidden = false) => /* @__PURE__ */ jsxs(Fragment, { children: [
4252
- /* @__PURE__ */ jsx(Label, { htmlFor: selectId, screenReaderOnly: true, children: label }),
4267
+ var _a, _b, _c, _d, _e;
4268
+ const fieldId = id || "theme-picker";
4269
+ const selectedValue = value ?? defaultValue ?? ((_a = themes[0]) == null ? void 0 : _a.value) ?? "";
4270
+ const select = () => /* @__PURE__ */ jsxs(Fragment, { children: [
4271
+ /* @__PURE__ */ jsx(Label, { htmlFor: fieldId, screenReaderOnly: true, children: label }),
4253
4272
  /* @__PURE__ */ jsx(
4254
4273
  "select",
4255
4274
  {
4256
- id: selectId,
4275
+ id: fieldId,
4257
4276
  name,
4258
- className: ClassNames(
4259
- "usa-select usx-select",
4260
- hidden && "usx-theme-picker__select--hidden"
4261
- ),
4262
- value: selectedValue,
4263
- onChange: (event) => choose(event.target.value),
4277
+ className: "usa-select usx-select",
4278
+ defaultValue: selectedValue,
4264
4279
  children: themes.map((option) => /* @__PURE__ */ jsx("option", { value: option.value, children: option.label }, option.value))
4265
4280
  }
4266
4281
  )
@@ -4274,6 +4289,7 @@ function ThemePicker({
4274
4289
  className
4275
4290
  ),
4276
4291
  ...extraAttributes,
4292
+ hidden: true,
4277
4293
  children: [
4278
4294
  variant === "default" && /* @__PURE__ */ jsxs(Fragment, { children: [
4279
4295
  /* @__PURE__ */ jsx(
@@ -4283,11 +4299,11 @@ function ThemePicker({
4283
4299
  className: "usa-button usx-button usx-button--ghost usx-theme-picker__trigger",
4284
4300
  "aria-label": label,
4285
4301
  "aria-expanded": "false",
4286
- "aria-controls": `${selectId}-panel`,
4302
+ "aria-controls": `${fieldId}-panel`,
4287
4303
  children: /* @__PURE__ */ jsx(Icon, { name: "color_palette", source: "usx", className: "usx-theme-picker__icon" })
4288
4304
  }
4289
4305
  ),
4290
- /* @__PURE__ */ jsxs("div", { id: `${selectId}-panel`, className: "usx-theme-picker__panel", children: [
4306
+ /* @__PURE__ */ jsxs("div", { id: `${fieldId}-panel`, className: "usx-theme-picker__panel", children: [
4291
4307
  select(),
4292
4308
  /* @__PURE__ */ jsx(
4293
4309
  "button",
@@ -4304,33 +4320,43 @@ function ThemePicker({
4304
4320
  /* @__PURE__ */ jsx(
4305
4321
  Swap,
4306
4322
  {
4307
- className: "usx-theme-picker__swap usa-button usx-button usx-button--ghost",
4323
+ as: "button",
4324
+ className: "usx-theme-picker__swap usx-button--ghost usx-button--tight",
4308
4325
  variant: "rotate",
4309
- inputProps: {
4310
- checked: selectedValue === ((_c = themes[1]) == null ? void 0 : _c.value),
4311
- "aria-label": `${label}: ${selectedLabel}. Switch to ${selectedValue === ((_d = themes[1]) == null ? void 0 : _d.value) ? (_e = themes[0]) == null ? void 0 : _e.label : (_f = themes[1]) == null ? void 0 : _f.label}`,
4312
- onChange: (event) => {
4313
- var _a2;
4314
- event.stopPropagation();
4315
- choose(((_a2 = themes[event.target.checked ? 1 : 0]) == null ? void 0 : _a2.value) ?? "");
4316
- }
4317
- },
4326
+ defaultPressed: selectedValue === ((_b = themes[1]) == null ? void 0 : _b.value),
4327
+ ariaLabel: `${((_c = themes[1]) == null ? void 0 : _c.label) ?? ""} ${label}`.trim(),
4328
+ "data-usx-theme-off": (_d = themes[0]) == null ? void 0 : _d.value,
4329
+ "data-usx-theme-on": (_e = themes[1]) == null ? void 0 : _e.value,
4318
4330
  offContent: /* @__PURE__ */ jsx(Icon, { name: "sun", source: "usx", className: "usx-theme-picker__icon" }),
4319
4331
  onContent: /* @__PURE__ */ jsx(Icon, { name: "moon", source: "usx", className: "usx-theme-picker__icon" })
4320
4332
  }
4321
4333
  ),
4322
- /* @__PURE__ */ jsx("div", { className: "usx-theme-picker__fallback", children: select() })
4334
+ /* @__PURE__ */ jsx("input", { id: fieldId, type: "hidden", name, defaultValue: selectedValue })
4323
4335
  ] }),
4324
- variant === "ghost-select" && /* @__PURE__ */ jsxs("div", { className: "usx-theme-picker__ghost", children: [
4336
+ variant === "popover" && /* @__PURE__ */ jsxs(Fragment, { children: [
4325
4337
  /* @__PURE__ */ jsx(
4326
- "span",
4338
+ Popover,
4327
4339
  {
4328
- className: "usa-button usx-button usx-button--ghost usx-theme-picker__ghost-face",
4329
- "aria-hidden": "true",
4330
- children: /* @__PURE__ */ jsx(Icon, { name: "color_palette", source: "usx", className: "usx-theme-picker__icon" })
4340
+ id: `${fieldId}-panel`,
4341
+ className: "usx-theme-picker__popover",
4342
+ align: popoverAlign,
4343
+ panelShape: "square",
4344
+ summaryProps: {
4345
+ className: "usa-button usx-button usx-button--ghost usx-button--tight margin-0",
4346
+ ariaLabel: label,
4347
+ children: /* @__PURE__ */ jsx(Icon, { name: "color_palette", source: "usx", className: "usx-theme-picker__icon" })
4348
+ },
4349
+ menuItems: themes.map((theme) => ({
4350
+ type: "button",
4351
+ text: theme.label,
4352
+ extraAttributes: {
4353
+ "data-usx-theme-value": theme.value,
4354
+ "aria-pressed": theme.value === selectedValue
4355
+ }
4356
+ }))
4331
4357
  }
4332
4358
  ),
4333
- select(true)
4359
+ /* @__PURE__ */ jsx("input", { id: fieldId, type: "hidden", name, defaultValue: selectedValue })
4334
4360
  ] })
4335
4361
  ]
4336
4362
  }
@@ -4530,6 +4556,7 @@ const Villain = ({
4530
4556
  };
4531
4557
  export {
4532
4558
  Accordion,
4559
+ AccordionItem,
4533
4560
  Alert,
4534
4561
  Attribution,
4535
4562
  Avatar,
@@ -4587,7 +4614,7 @@ export {
4587
4614
  Modal,
4588
4615
  Page,
4589
4616
  Pagination,
4590
- P as Popover,
4617
+ Popover,
4591
4618
  ProcessList,
4592
4619
  Prose,
4593
4620
  Quote,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@solexllc/usx-react",
3
- "version": "0.12.0",
3
+ "version": "1.0.0",
4
4
  "description": "React component library for USX.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -29,9 +29,9 @@
29
29
  "dist"
30
30
  ],
31
31
  "dependencies": {
32
- "@solexllc/usx": "0.14.0",
33
- "@solexllc/usx-theme": "0.11.2",
34
- "@solexllc/usx-uswds-fixes": "0.1.17",
32
+ "@solexllc/usx": "1.0.0",
33
+ "@solexllc/usx-theme": "1.0.0",
34
+ "@solexllc/usx-uswds-fixes": "0.1.18",
35
35
  "classnames": "^2.5.1",
36
36
  "prop-types": "^15.8.1"
37
37
  },
@@ -1,70 +1,21 @@
1
1
  import React from 'react';
2
2
  import classnames from 'classnames';
3
+ import AccordionItem from '../accordion-item/AccordionItem';
4
+ import type { AccordionHeadingAs, AccordionItemProps } from '../accordion-item/AccordionItem';
3
5
 
4
- export type AccordionHeadingAs = 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6';
5
-
6
- export interface AccordionItemProps {
7
- title: React.ReactNode;
8
- id: string;
9
- content: React.ReactNode;
10
- expanded?: boolean;
11
- headingClassName?: string;
12
- contentClassName?: string;
13
- headingAs?: AccordionHeadingAs;
14
- handleToggle?: React.MouseEventHandler<HTMLButtonElement>;
15
- }
6
+ export type { AccordionHeadingAs, AccordionItemProps } from '../accordion-item/AccordionItem';
16
7
 
17
8
  export interface AccordionProps extends React.HTMLAttributes<HTMLDivElement> {
18
9
  extraAttributes?: Record<string, unknown>;
19
10
  bordered?: boolean;
20
- items?: AccordionItemProps[];
11
+ items?: (Omit<AccordionItemProps, 'id'> & { id?: string })[];
21
12
  multiselectable?: boolean;
22
13
  headingAs?: AccordionHeadingAs;
23
14
  iconPosition?: 'start' | 'end';
15
+ headingClassName?: string;
16
+ contentClassName?: string;
24
17
  }
25
18
 
26
- function AccordionItem({
27
- title,
28
- id,
29
- content,
30
- expanded = false,
31
- headingClassName,
32
- contentClassName,
33
- headingAs = 'h3',
34
- handleToggle,
35
- }: AccordionItemProps) {
36
- const headingClasses = classnames('usa-accordion__heading', headingClassName)
37
- const contentClasses = classnames(
38
- 'usa-accordion__content',
39
- 'usa-prose',
40
- contentClassName
41
- )
42
-
43
- const Heading = headingAs
44
-
45
- return (
46
- <>
47
- <Heading id={`${id}-heading`} className={headingClasses}>
48
- <button
49
- type="button"
50
- className="usa-accordion__button"
51
- aria-expanded={expanded}
52
- aria-controls={`${id}-content`}
53
- onClick={handleToggle}>
54
- {title}
55
- </button>
56
- </Heading>
57
- <div
58
- id={`${id}-content`}
59
- aria-labelledby={`${id}-heading`}
60
- className={contentClasses}
61
- hidden={!expanded}>
62
- {content}
63
- </div>
64
- </>
65
- )
66
- };
67
-
68
19
  export function Accordion({
69
20
  id,
70
21
  bordered = false,
@@ -95,10 +46,11 @@ export function Accordion({
95
46
  {...props}
96
47
  {...extraAttributes}
97
48
  >
98
- {items.map((item) => (
49
+ {items.map((item, index) => (
99
50
  <AccordionItem
100
- key={item.id}
51
+ key={item.id || `${id ?? ''}-${index}`}
101
52
  {...item}
53
+ id={item.id || `${id ?? ''}-${index}`}
102
54
  headingAs={headingAs}
103
55
  headingClassName={headingClassName}
104
56
  contentClassName={contentClassName}
@@ -1,3 +1,4 @@
1
+ {% load usx_components %}
1
2
  <div
2
3
  id="{{ id }}"
3
4
  class="usa-accordion usx-accordion {% if bordered %}usa-accordion--bordered{% endif %}{% if iconPosition == 'start' %} usa-accordion--icon-start{% elif iconPosition == 'end' %} usa-accordion--icon-end{% endif %}{% if className %} {{ className }}{% endif %}" {% if extraAttributes %}{% for attr, value in extraAttributes.items %} {{ attr }}="{% if value is True %}true{% elif value is False %}false{% else %}{{ value }}{% endif %}"{% endfor %}{% endif %}
@@ -6,26 +7,15 @@
6
7
  {% endif %}
7
8
  >
8
9
  {% for item in items %}
9
- <{% if headingAs == 'h1' %}h1{% elif headingAs == 'h2' %}h2{% elif headingAs == 'h4' %}h4{% elif headingAs == 'h5' %}h5{% elif headingAs == 'h6' %}h6{% else %}h3{% endif %} id="{% if item.id %}{{ item.id }}{% else %}{{ id }}-{{ forloop.counter0 }}{% endif %}-heading" class="usa-accordion__heading{% if headingClassName %} {{ headingClassName }}{% endif %}">
10
- <button
11
- class="usa-accordion__button"
12
- aria-expanded="{% if item.expanded %}true{% else %}false{% endif %}"
13
- aria-controls="{% if item.id %}{{ item.id }}{% else %}{{ id }}-{{ forloop.counter0 }}{% endif %}-content"
14
- type="button"
15
- >
16
- {{ item.title }}
17
- </button>
18
- </{% if headingAs == 'h1' %}h1{% elif headingAs == 'h2' %}h2{% elif headingAs == 'h4' %}h4{% elif headingAs == 'h5' %}h5{% elif headingAs == 'h6' %}h6{% else %}h3{% endif %}>
19
-
20
- <div
21
- id="{% if item.id %}{{ item.id }}{% else %}{{ id }}-{{ forloop.counter0 }}{% endif %}-content"
22
- class="usa-accordion__content usa-prose{% if contentClassName %} {{ contentClassName }}{% endif %}"
23
- aria-labelledby="{% if item.id %}{{ item.id }}{% else %}{{ id }}-{{ forloop.counter0 }}{% endif %}-heading"
24
- {% if not item.expanded %}hidden{% endif %}
25
- >
26
- {{ item.content }}
27
- </div>
28
-
10
+ {% if item.id %}
11
+ {% accordion_item props=item id=item.id headingAs=headingAs headingClassName=headingClassName contentClassName=contentClassName %}{% endaccordion_item %}
12
+ {% else %}
13
+ {% with index=forloop.counter0|stringformat:"s" %}
14
+ {% with baseId=id|default:""|add:"-"|add:index %}
15
+ {% accordion_item props=item id=baseId headingAs=headingAs headingClassName=headingClassName contentClassName=contentClassName %}{% endaccordion_item %}
16
+ {% endwith %}
17
+ {% endwith %}
18
+ {% endif %}
29
19
  {% endfor %}
30
20
 
31
21
  </div>
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "accordion",
3
3
  "template": "accordion/accordion.django.html",
4
- "version": 3,
4
+ "version": 4,
5
5
  "default": {
6
6
  "id": "accordion-default",
7
7
  "items": [
@@ -36,7 +36,13 @@
36
36
  "items": {
37
37
  "type": "array",
38
38
  "default": [],
39
- "description": "An array of accordion items. Each item sets title and content, and may set id (used for the heading and content ids) and expanded (start open)."
39
+ "description": "Accordion items. The parent supplies the heading element and heading/content classes for every item.",
40
+ "items": {
41
+ "type": "object",
42
+ "description": "Props for one accordion item. If id is omitted, the accordion id and item index are used.",
43
+ "component": "accordion-item",
44
+ "omit": ["headingAs", "headingClassName", "contentClassName"]
45
+ }
40
46
  },
41
47
  "multiselectable": {
42
48
  "type": "boolean",
@@ -0,0 +1,54 @@
1
+ import React from 'react';
2
+ import classnames from 'classnames';
3
+
4
+ export type AccordionHeadingAs = 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6';
5
+
6
+ export interface AccordionItemProps {
7
+ title: React.ReactNode;
8
+ id: string;
9
+ content?: React.ReactNode;
10
+ children?: React.ReactNode;
11
+ expanded?: boolean;
12
+ headingClassName?: string;
13
+ contentClassName?: string;
14
+ headingAs?: AccordionHeadingAs;
15
+ handleToggle?: React.MouseEventHandler<HTMLButtonElement>;
16
+ }
17
+
18
+ export default function AccordionItem({
19
+ title,
20
+ id,
21
+ content,
22
+ children,
23
+ expanded = false,
24
+ headingClassName,
25
+ contentClassName,
26
+ headingAs = 'h3',
27
+ handleToggle,
28
+ }: AccordionItemProps) {
29
+ const headingClasses = classnames('usa-accordion__heading', headingClassName);
30
+ const contentClasses = classnames('usa-accordion__content', 'usa-prose', contentClassName);
31
+ const Heading = headingAs;
32
+
33
+ return (
34
+ <>
35
+ <Heading id={`${id}-heading`} className={headingClasses}>
36
+ <button
37
+ type="button"
38
+ className="usa-accordion__button"
39
+ aria-expanded={expanded}
40
+ aria-controls={`${id}-content`}
41
+ onClick={handleToggle}>
42
+ {title}
43
+ </button>
44
+ </Heading>
45
+ <div
46
+ id={`${id}-content`}
47
+ aria-labelledby={`${id}-heading`}
48
+ className={contentClasses}
49
+ hidden={!expanded}>
50
+ {children ?? content}
51
+ </div>
52
+ </>
53
+ );
54
+ }
@@ -0,0 +1,19 @@
1
+ <{% if headingAs == 'h1' %}h1{% elif headingAs == 'h2' %}h2{% elif headingAs == 'h4' %}h4{% elif headingAs == 'h5' %}h5{% elif headingAs == 'h6' %}h6{% else %}h3{% endif %} id="{{ id }}-heading" class="usa-accordion__heading{% if headingClassName %} {{ headingClassName }}{% endif %}">
2
+ <button
3
+ class="usa-accordion__button"
4
+ aria-expanded="{% if expanded %}true{% else %}false{% endif %}"
5
+ aria-controls="{{ id }}-content"
6
+ type="button"
7
+ >
8
+ {% if title is not None and title is not True and title is not False %}{{ title }}{% endif %}
9
+ </button>
10
+ </{% if headingAs == 'h1' %}h1{% elif headingAs == 'h2' %}h2{% elif headingAs == 'h4' %}h4{% elif headingAs == 'h5' %}h5{% elif headingAs == 'h6' %}h6{% else %}h3{% endif %}>
11
+
12
+ <div
13
+ id="{{ id }}-content"
14
+ class="usa-accordion__content usa-prose{% if contentClassName %} {{ contentClassName }}{% endif %}"
15
+ aria-labelledby="{{ id }}-heading"
16
+ {% if not expanded %}hidden{% endif %}
17
+ >
18
+ {% if children is not None %}{% if children is not True and children is not False %}{{ children }}{% endif %}{% elif content is not None and content is not True and content is not False %}{{ content }}{% endif %}
19
+ </div>
@@ -0,0 +1,8 @@
1
+ <h3 id="accordion-item-example-heading" class="usa-accordion__heading">
2
+ <button type="button" class="usa-accordion__button" aria-expanded="false" aria-controls="accordion-item-example-content">
3
+ Accordion item
4
+ </button>
5
+ </h3>
6
+ <div id="accordion-item-example-content" class="usa-accordion__content usa-prose" aria-labelledby="accordion-item-example-heading" hidden>
7
+ Accordion item content.
8
+ </div>
@@ -0,0 +1,55 @@
1
+ {
2
+ "name": "accordion-item",
3
+ "template": "accordion-item/accordion-item.django.html",
4
+ "version": 1,
5
+ "required": ["id", "title"],
6
+ "default": {
7
+ "id": "accordion-item-example",
8
+ "title": "Accordion item",
9
+ "content": "Accordion item content."
10
+ },
11
+ "props": {
12
+ "id": {
13
+ "type": "string",
14
+ "description": "Unique base ID for the heading and content."
15
+ },
16
+ "title": {
17
+ "type": "slot",
18
+ "description": "Content of the accordion heading button."
19
+ },
20
+ "content": {
21
+ "type": "slot",
22
+ "description": "Content of the accordion panel. Ignored when children is provided."
23
+ },
24
+ "children": {
25
+ "type": "slot",
26
+ "description": "Content of the accordion panel. Takes precedence over content when provided."
27
+ },
28
+ "expanded": {
29
+ "type": "boolean",
30
+ "default": false,
31
+ "description": "Whether the panel starts expanded."
32
+ },
33
+ "headingAs": {
34
+ "type": "select",
35
+ "options": ["h1", "h2", "h3", "h4", "h5", "h6"],
36
+ "default": "h3",
37
+ "description": "Heading element wrapping the button. In Accordion, the parent controls this value."
38
+ },
39
+ "headingClassName": {
40
+ "type": "string",
41
+ "description": "Additional heading classes. In Accordion, the parent controls this value."
42
+ },
43
+ "contentClassName": {
44
+ "type": "string",
45
+ "description": "Additional panel classes. In Accordion, the parent controls this value."
46
+ },
47
+ "handleToggle": {
48
+ "type": "function",
49
+ "description": "React click handler for the heading button.",
50
+ "renderers": {
51
+ "django": { "supported": false, "description": "Callbacks cannot be rendered by Django." }
52
+ }
53
+ }
54
+ }
55
+ }