@solexllc/usx-react 0.1.7 → 0.1.8

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/index.cjs CHANGED
@@ -2631,15 +2631,19 @@
2631
2631
  }
2632
2632
  );
2633
2633
  }
2634
- function SingleColumnLayout({ children, className = "", ...props }) {
2634
+ function SingleColumnLayout({ children, expandButton = null, className = "", ...props }) {
2635
2635
  const classes = ["usx-layout__single-column", className].filter(Boolean).join(" ");
2636
- return /* @__PURE__ */ jsxRuntime.jsx("div", { className: classes, ...props, children });
2636
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: classes, ...props, children: [
2637
+ expandButton,
2638
+ children
2639
+ ] });
2637
2640
  }
2638
2641
  function GridLayout({
2639
2642
  leftSidebar,
2640
2643
  rightSidebar,
2641
2644
  expandLeftSidebar,
2642
2645
  expandRightSidebar,
2646
+ expandButton = null,
2643
2647
  children,
2644
2648
  className = "",
2645
2649
  ...props
@@ -2670,7 +2674,10 @@
2670
2674
  );
2671
2675
  return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: containerClasses, ...props, children: [
2672
2676
  leftSidebar && /* @__PURE__ */ jsxRuntime.jsx("aside", { className: leftSidebarClasses, children: leftSidebar }),
2673
- /* @__PURE__ */ jsxRuntime.jsx("main", { className: contentClasses, children }),
2677
+ /* @__PURE__ */ jsxRuntime.jsxs("main", { className: contentClasses, children: [
2678
+ expandButton,
2679
+ children
2680
+ ] }),
2674
2681
  rightSidebar && /* @__PURE__ */ jsxRuntime.jsx("aside", { className: rightSidebarClasses, children: rightSidebar })
2675
2682
  ] });
2676
2683
  }
@@ -2682,23 +2689,43 @@
2682
2689
  rightSidebar,
2683
2690
  expandLeftSidebar,
2684
2691
  expandRightSidebar,
2692
+ expandable = false,
2685
2693
  className = "",
2686
2694
  ...props
2687
2695
  }) {
2696
+ const [expanded, setExpanded] = React.useState(false);
2688
2697
  const classes = classNames(
2689
2698
  "usx-layout",
2699
+ { "usx-expanded": expandable && expanded },
2690
2700
  className
2691
2701
  );
2692
- return /* @__PURE__ */ jsxRuntime.jsx("div", { className: classes, ...props, children: variant === "single-column" ? /* @__PURE__ */ jsxRuntime.jsx(SingleColumnLayout, { children: children || content }) : variant === "grid" ? /* @__PURE__ */ jsxRuntime.jsx(
2702
+ const expandButton = expandable ? /* @__PURE__ */ jsxRuntime.jsxs(
2703
+ Button,
2704
+ {
2705
+ variant: "primary",
2706
+ ghost: true,
2707
+ className: "usx-layout__expand-button",
2708
+ onClick: () => setExpanded((value) => !value),
2709
+ children: [
2710
+ /* @__PURE__ */ jsxRuntime.jsx(Icon, { source: "usx", name: "expand", size: 3, className: "usx-layout__expand-icon usx-layout__expand-icon--expand" }),
2711
+ /* @__PURE__ */ jsxRuntime.jsx(Icon, { source: "usx", name: "contract", size: 3, className: "usx-layout__expand-icon usx-layout__expand-icon--contract" })
2712
+ ]
2713
+ }
2714
+ ) : null;
2715
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { className: classes, ...props, children: variant === "single-column" ? /* @__PURE__ */ jsxRuntime.jsx(SingleColumnLayout, { expandButton, children: children || content }) : variant === "grid" ? /* @__PURE__ */ jsxRuntime.jsx(
2693
2716
  GridLayout,
2694
2717
  {
2695
2718
  leftSidebar,
2696
2719
  rightSidebar,
2697
2720
  expandLeftSidebar,
2698
2721
  expandRightSidebar,
2722
+ expandButton,
2699
2723
  children: children || content
2700
2724
  }
2701
- ) : children || content });
2725
+ ) : /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
2726
+ expandButton,
2727
+ children || content
2728
+ ] }) });
2702
2729
  }
2703
2730
  function isItemObject(item) {
2704
2731
  return item && typeof item === "object" && !Array.isArray(item) && !React.isValidElement(item);
@@ -3046,6 +3073,7 @@
3046
3073
  id = void 0,
3047
3074
  title = "Page title",
3048
3075
  eyebrow = null,
3076
+ element = "main",
3049
3077
  children = null,
3050
3078
  content = null,
3051
3079
  className = "",
@@ -3053,7 +3081,8 @@
3053
3081
  }) {
3054
3082
  const classes = ["usx-page", className].filter(Boolean).join(" ");
3055
3083
  const pageContent = children || content;
3056
- return /* @__PURE__ */ jsxRuntime.jsxs("main", { id, className: classes, ...props, children: [
3084
+ const Element = element;
3085
+ return /* @__PURE__ */ jsxRuntime.jsxs(Element, { id, className: classes, ...props, children: [
3057
3086
  /* @__PURE__ */ jsxRuntime.jsxs("h1", { className: "usx-page__title", children: [
3058
3087
  eyebrow ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "usx-eyebrow", children: eyebrow }) : null,
3059
3088
  title
package/dist/index.js CHANGED
@@ -2629,15 +2629,19 @@ function LanguageSelector({
2629
2629
  }
2630
2630
  );
2631
2631
  }
2632
- function SingleColumnLayout({ children, className = "", ...props }) {
2632
+ function SingleColumnLayout({ children, expandButton = null, className = "", ...props }) {
2633
2633
  const classes = ["usx-layout__single-column", className].filter(Boolean).join(" ");
2634
- return /* @__PURE__ */ jsx("div", { className: classes, ...props, children });
2634
+ return /* @__PURE__ */ jsxs("div", { className: classes, ...props, children: [
2635
+ expandButton,
2636
+ children
2637
+ ] });
2635
2638
  }
2636
2639
  function GridLayout({
2637
2640
  leftSidebar,
2638
2641
  rightSidebar,
2639
2642
  expandLeftSidebar,
2640
2643
  expandRightSidebar,
2644
+ expandButton = null,
2641
2645
  children,
2642
2646
  className = "",
2643
2647
  ...props
@@ -2668,7 +2672,10 @@ function GridLayout({
2668
2672
  );
2669
2673
  return /* @__PURE__ */ jsxs("div", { className: containerClasses, ...props, children: [
2670
2674
  leftSidebar && /* @__PURE__ */ jsx("aside", { className: leftSidebarClasses, children: leftSidebar }),
2671
- /* @__PURE__ */ jsx("main", { className: contentClasses, children }),
2675
+ /* @__PURE__ */ jsxs("main", { className: contentClasses, children: [
2676
+ expandButton,
2677
+ children
2678
+ ] }),
2672
2679
  rightSidebar && /* @__PURE__ */ jsx("aside", { className: rightSidebarClasses, children: rightSidebar })
2673
2680
  ] });
2674
2681
  }
@@ -2680,23 +2687,43 @@ function Layout({
2680
2687
  rightSidebar,
2681
2688
  expandLeftSidebar,
2682
2689
  expandRightSidebar,
2690
+ expandable = false,
2683
2691
  className = "",
2684
2692
  ...props
2685
2693
  }) {
2694
+ const [expanded, setExpanded] = useState(false);
2686
2695
  const classes = classNames(
2687
2696
  "usx-layout",
2697
+ { "usx-expanded": expandable && expanded },
2688
2698
  className
2689
2699
  );
2690
- return /* @__PURE__ */ jsx("div", { className: classes, ...props, children: variant === "single-column" ? /* @__PURE__ */ jsx(SingleColumnLayout, { children: children || content }) : variant === "grid" ? /* @__PURE__ */ jsx(
2700
+ const expandButton = expandable ? /* @__PURE__ */ jsxs(
2701
+ Button,
2702
+ {
2703
+ variant: "primary",
2704
+ ghost: true,
2705
+ className: "usx-layout__expand-button",
2706
+ onClick: () => setExpanded((value) => !value),
2707
+ children: [
2708
+ /* @__PURE__ */ jsx(Icon, { source: "usx", name: "expand", size: 3, className: "usx-layout__expand-icon usx-layout__expand-icon--expand" }),
2709
+ /* @__PURE__ */ jsx(Icon, { source: "usx", name: "contract", size: 3, className: "usx-layout__expand-icon usx-layout__expand-icon--contract" })
2710
+ ]
2711
+ }
2712
+ ) : null;
2713
+ return /* @__PURE__ */ jsx("div", { className: classes, ...props, children: variant === "single-column" ? /* @__PURE__ */ jsx(SingleColumnLayout, { expandButton, children: children || content }) : variant === "grid" ? /* @__PURE__ */ jsx(
2691
2714
  GridLayout,
2692
2715
  {
2693
2716
  leftSidebar,
2694
2717
  rightSidebar,
2695
2718
  expandLeftSidebar,
2696
2719
  expandRightSidebar,
2720
+ expandButton,
2697
2721
  children: children || content
2698
2722
  }
2699
- ) : children || content });
2723
+ ) : /* @__PURE__ */ jsxs(Fragment, { children: [
2724
+ expandButton,
2725
+ children || content
2726
+ ] }) });
2700
2727
  }
2701
2728
  function isItemObject(item) {
2702
2729
  return item && typeof item === "object" && !Array.isArray(item) && !React.isValidElement(item);
@@ -3044,6 +3071,7 @@ function Page({
3044
3071
  id = void 0,
3045
3072
  title = "Page title",
3046
3073
  eyebrow = null,
3074
+ element = "main",
3047
3075
  children = null,
3048
3076
  content = null,
3049
3077
  className = "",
@@ -3051,7 +3079,8 @@ function Page({
3051
3079
  }) {
3052
3080
  const classes = ["usx-page", className].filter(Boolean).join(" ");
3053
3081
  const pageContent = children || content;
3054
- return /* @__PURE__ */ jsxs("main", { id, className: classes, ...props, children: [
3082
+ const Element = element;
3083
+ return /* @__PURE__ */ jsxs(Element, { id, className: classes, ...props, children: [
3055
3084
  /* @__PURE__ */ jsxs("h1", { className: "usx-page__title", children: [
3056
3085
  eyebrow ? /* @__PURE__ */ jsx("span", { className: "usx-eyebrow", children: eyebrow }) : null,
3057
3086
  title
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@solexllc/usx-react",
3
- "version": "0.1.7",
3
+ "version": "0.1.8",
4
4
  "description": "React component library for USX.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -25,9 +25,9 @@
25
25
  "dist"
26
26
  ],
27
27
  "dependencies": {
28
- "@solexllc/usx": "0.1.7",
29
- "@solexllc/usx-theme": "0.2.2",
30
- "@solexllc/usx-uswds-fixes": "0.1.4",
28
+ "@solexllc/usx": "0.1.8",
29
+ "@solexllc/usx-theme": "0.2.3",
30
+ "@solexllc/usx-uswds-fixes": "0.1.5",
31
31
  "classnames": "^2.5.1",
32
32
  "prop-types": "^15.8.1"
33
33
  },
@@ -1,17 +1,22 @@
1
- import React, { ReactNode, HTMLAttributes } from 'react';
1
+ import React, { useState, ReactNode, HTMLAttributes } from 'react';
2
2
  import ClassNames from 'classnames';
3
+ import Icon from '../icon/Icon';
4
+ import Button from '../button/Button';
5
+ import Tooltip from '../tooltip/Tooltip';
3
6
 
4
7
  // ── Sub-components ──────────────────────────────────────────────────────────
5
8
 
6
9
  export interface SingleColumnLayoutProps extends HTMLAttributes<HTMLDivElement> {
7
10
  children?: ReactNode;
11
+ expandButton?: ReactNode;
8
12
  className?: string;
9
13
  }
10
14
 
11
- export function SingleColumnLayout({ children, className = '', ...props }: SingleColumnLayoutProps) {
15
+ export function SingleColumnLayout({ children, expandButton = null, className = '', ...props }: SingleColumnLayoutProps) {
12
16
  const classes = ['usx-layout__single-column', className].filter(Boolean).join(' ');
13
17
  return (
14
18
  <div className={classes} {...props}>
19
+ {expandButton}
15
20
  {children}
16
21
  </div>
17
22
  );
@@ -22,6 +27,7 @@ export type GridLayoutProps = {
22
27
  rightSidebar?: ReactNode;
23
28
  expandLeftSidebar?: boolean;
24
29
  expandRightSidebar?: boolean;
30
+ expandButton?: ReactNode;
25
31
  children?: ReactNode;
26
32
  className?: string;
27
33
  } & HTMLAttributes<HTMLDivElement>;
@@ -31,14 +37,15 @@ export function GridLayout({
31
37
  rightSidebar,
32
38
  expandLeftSidebar,
33
39
  expandRightSidebar,
40
+ expandButton = null,
34
41
  children,
35
42
  className = '',
36
43
  ...props
37
44
  }: GridLayoutProps) {
38
45
  const contentModifier = (
39
46
  rightSidebar && !leftSidebar ? 'left'
40
- : leftSidebar && !rightSidebar ? 'right'
41
- : null
47
+ : leftSidebar && !rightSidebar ? 'right'
48
+ : null
42
49
  );
43
50
 
44
51
  const contentClasses = ClassNames(
@@ -70,7 +77,10 @@ export function GridLayout({
70
77
  {leftSidebar && (
71
78
  <aside className={leftSidebarClasses}>{leftSidebar}</aside>
72
79
  )}
73
- <main className={contentClasses}>{children}</main>
80
+ <main className={contentClasses}>
81
+ {expandButton}
82
+ {children}
83
+ </main>
74
84
  {rightSidebar && (
75
85
  <aside className={rightSidebarClasses}>{rightSidebar}</aside>
76
86
  )}
@@ -89,6 +99,8 @@ export type LayoutProps = {
89
99
  rightSidebar?: ReactNode;
90
100
  expandLeftSidebar?: boolean;
91
101
  expandRightSidebar?: boolean;
102
+ /** Adds a toggle button that grows the layout to a wider max-width via the `usx-expanded` class. */
103
+ expandable?: boolean;
92
104
  className?: string;
93
105
  } & HTMLAttributes<HTMLDivElement>;
94
106
 
@@ -100,18 +112,35 @@ export default function Layout({
100
112
  rightSidebar,
101
113
  expandLeftSidebar,
102
114
  expandRightSidebar,
115
+ expandable = false,
103
116
  className = '',
104
117
  ...props
105
118
  }: LayoutProps) {
119
+ const [expanded, setExpanded] = useState(false);
106
120
  const classes = ClassNames(
107
121
  'usx-layout',
122
+ { 'usx-expanded': expandable && expanded },
108
123
  className,
109
124
  );
110
125
 
126
+ const expandButton = expandable ? (
127
+
128
+ <Button
129
+ variant="primary"
130
+ ghost={true}
131
+ className="usx-layout__expand-button"
132
+ onClick={() => setExpanded((value) => !value)}
133
+ >
134
+ <Icon source="usx" name="expand" size={3} className="usx-layout__expand-icon usx-layout__expand-icon--expand" />
135
+ <Icon source="usx" name="contract" size={3} className="usx-layout__expand-icon usx-layout__expand-icon--contract" />
136
+ </Button>
137
+
138
+ ) : null;
139
+
111
140
  return (
112
141
  <div className={classes} {...props}>
113
142
  {variant === 'single-column' ? (
114
- <SingleColumnLayout>
143
+ <SingleColumnLayout expandButton={expandButton}>
115
144
  {children || content}
116
145
  </SingleColumnLayout>
117
146
  ) : variant === 'grid' ? (
@@ -120,11 +149,15 @@ export default function Layout({
120
149
  rightSidebar={rightSidebar}
121
150
  expandLeftSidebar={expandLeftSidebar}
122
151
  expandRightSidebar={expandRightSidebar}
152
+ expandButton={expandButton}
123
153
  >
124
154
  {children || content}
125
155
  </GridLayout>
126
156
  ) : (
127
- children || content
157
+ <>
158
+ {expandButton}
159
+ {children || content}
160
+ </>
128
161
  )}
129
162
  </div>
130
163
  );
@@ -28,6 +28,10 @@
28
28
  "type": "string",
29
29
  "description": "Right sidebar content (grid variant only)"
30
30
  },
31
+ "expandable": {
32
+ "type": "boolean",
33
+ "description": "Adds a toggle button that grows the layout to a wider max-width via the usx-expanded class."
34
+ },
31
35
  "className": {
32
36
  "type": "string",
33
37
  "description": "Additional CSS classes"
@@ -1,9 +1,20 @@
1
+ {% load components %}
1
2
  {# Django template for Layout #}
2
3
  {# Supports variant: 'single-column' (default), 'grid' #}
3
4
  {# For grid: content, leftSidebar, rightSidebar #}
5
+ {% fragment as expandButton %}
6
+ {% if expandable %}
7
+ {% html_attrs aria_expanded="false" aria_label="Expand" onclick="const layout = this.closest('.usx-layout'); const expanded = layout.classList.toggle('usx-expanded'); this.setAttribute('aria-expanded', expanded); this.setAttribute('aria-label', expanded ? 'Contract' : 'Expand');" as expandAttributes %}
8
+ {% button variant="primary" ghost=True type="button" className="usx-layout__expand-button" extraAttributes=expandAttributes %}
9
+ {% icon source='usx' name='expand' size=3 className='usx-layout__expand-icon usx-layout__expand-icon--expand' %}{% endicon %}
10
+ {% icon source='usx' name='contract' size=3 className='usx-layout__expand-icon usx-layout__expand-icon--contract' %}{% endicon %}
11
+ {% endbutton %}
12
+ {% endif %}
13
+ {% endfragment %}
4
14
  <div class="usx-layout{% if className %} {{ className }}{% endif %}">
5
15
  {% if variant == 'single-column' %}
6
16
  <div class="usx-layout__single-column">
17
+ {{ expandButton }}
7
18
  {% if children %}{{ children|safe }}{% else %}{{ content|safe }}{% endif %}
8
19
  </div>
9
20
  {% elif variant == 'grid' %}
@@ -14,6 +25,7 @@
14
25
  </aside>
15
26
  {% endif %}
16
27
  <main class="usx-layout__content{% if rightSidebar and not leftSidebar %} usx-layout__content--left{% elif leftSidebar and not rightSidebar %} usx-layout__content--right{% endif %}">
28
+ {{ expandButton }}
17
29
  {% if children %}{{ children|safe }}{% else %}{{ content|safe }}{% endif %}
18
30
  </main>
19
31
  {% if rightSidebar %}
@@ -23,6 +35,7 @@
23
35
  {% endif %}
24
36
  </div>
25
37
  {% else %}
38
+ {{ expandButton }}
26
39
  {% if children %}{{ children|safe }}{% else %}{{ content|safe }}{% endif %}
27
40
  {% endif %}
28
41
  </div>
@@ -27,3 +27,19 @@
27
27
  </main>
28
28
  </div>
29
29
  </div>
30
+
31
+ <!-- Expandable Layout Example -->
32
+ <div class="usx-layout">
33
+ <button type="button" class="usx-layout__expand-button" aria-expanded="false" aria-label="Expand">
34
+ <svg class="usa-icon usx-layout__expand-icon usx-layout__expand-icon--expand" aria-hidden="true" focusable="false" role="img">
35
+ <use href="./img/usx-sprite.svg#expand"></use>
36
+ </svg>
37
+ <svg class="usa-icon usx-layout__expand-icon usx-layout__expand-icon--contract" aria-hidden="true" focusable="false" role="img">
38
+ <use href="./img/usx-sprite.svg#contract"></use>
39
+ </svg>
40
+ </button>
41
+ <div class="usx-layout__single-column">
42
+ <h1>Page Title</h1>
43
+ <p>Use the expand button in the top-right corner to grow the layout to a wider max-width.</p>
44
+ </div>
45
+ </div>
@@ -3,6 +3,7 @@ import React from 'react';
3
3
  export interface PageProps extends Omit<React.HTMLAttributes<HTMLElement>, 'title' | 'content'> {
4
4
  title?: React.ReactNode;
5
5
  eyebrow?: React.ReactNode;
6
+ element?: React.ElementType;
6
7
  content?: React.ReactNode;
7
8
  }
8
9
 
@@ -10,6 +11,7 @@ export default function Page({
10
11
  id = undefined,
11
12
  title = 'Page title',
12
13
  eyebrow = null,
14
+ element = 'main',
13
15
  children = null,
14
16
  content = null,
15
17
  className = '',
@@ -18,13 +20,15 @@ export default function Page({
18
20
  const classes = ['usx-page', className].filter(Boolean).join(' ');
19
21
  const pageContent = children || content;
20
22
 
23
+ const Element = element;
24
+
21
25
  return (
22
- <main id={id} className={classes} {...props}>
26
+ <Element id={id} className={classes} {...props}>
23
27
  <h1 className="usx-page__title">
24
28
  {eyebrow ? <span className="usx-eyebrow">{eyebrow}</span> : null}
25
29
  {title}
26
30
  </h1>
27
31
  <div className="usx-page__content">{pageContent}</div>
28
- </main>
32
+ </Element>
29
33
  );
30
34
  }