@sps-woodland/column-manager 7.5.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.
package/README.md ADDED
@@ -0,0 +1,3 @@
1
+ ## [@sps-woodland/column-manager](https://github.com/SPSCommerce/woodland/tree/master/packages/@sps-woodland/column-manager#readme)
2
+
3
+ SPS Woodland Design System Column Manager
@@ -0,0 +1,2 @@
1
+ import type { ComponentManifestEntry } from "@sps-woodland/core";
2
+ export declare const ColumnManagerExamples: ComponentManifestEntry;
@@ -0,0 +1,19 @@
1
+ import type { ComponentProps } from "@sps-woodland/core";
2
+ import type { ItemProps } from "@sps-woodland/add-to-list";
3
+ export type ColumnmanagerProps = ComponentProps<{
4
+ isOpen?: boolean;
5
+ title?: string;
6
+ visibleColumnsHeader?: string;
7
+ hiddenColumnsHeader?: string;
8
+ visibleColumns: ItemProps[];
9
+ hiddenColumns: ItemProps[];
10
+ manualSort?: boolean;
11
+ showIcons?: boolean;
12
+ showCount?: boolean;
13
+ showFilter?: boolean;
14
+ showMoveAllLinks?: boolean;
15
+ onSave?: (visibleColumns: ItemProps[], hiddenColumns: ItemProps[]) => void;
16
+ onClose?: () => void;
17
+ onOpen?: () => void;
18
+ }>;
19
+ export declare function ColumnManager({ isOpen: isOpenProp, title, visibleColumnsHeader, hiddenColumnsHeader, visibleColumns, hiddenColumns, manualSort, showIcons, showCount, showFilter, showMoveAllLinks, onSave, onOpen, onClose, "data-testid": dataTestId, }: ColumnmanagerProps): JSX.Element | null;
@@ -0,0 +1,26 @@
1
+ import type { ItemProps } from "@sps-woodland/add-to-list";
2
+ export interface UseColumnManagerArgs {
3
+ visibleColumns: ItemProps[];
4
+ hiddenColumns: ItemProps[];
5
+ isOpen?: boolean;
6
+ onClose?: () => void;
7
+ onOpen?: () => void;
8
+ onSave?: (visibleColumns: ItemProps[], hiddenColumns: ItemProps[]) => void;
9
+ }
10
+ export declare const useColumnManager: ({ isOpen: isOpenArg, visibleColumns, hiddenColumns, onClose, onOpen, onSave, }: UseColumnManagerArgs) => {
11
+ visibleColumns: ItemProps[];
12
+ hiddenColumns: ItemProps[];
13
+ isOpen: boolean;
14
+ columnManagerProps: {
15
+ visibleColumns: ItemProps[];
16
+ hiddenColumns: ItemProps[];
17
+ isOpen: boolean;
18
+ onClose: () => void;
19
+ onSave: (visible: ItemProps[], hidden: ItemProps[]) => void;
20
+ };
21
+ triggerProps: {
22
+ onClick: () => void;
23
+ };
24
+ setColumns: (visible: ItemProps[], hidden: ItemProps[]) => void;
25
+ setOpen: (open: boolean) => void;
26
+ };
@@ -0,0 +1,179 @@
1
+ "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const T=require("react"),P=require("@sps-woodland/core"),B=require("@sps-woodland/add-to-list"),R=require("@sps-woodland/tokens"),b=require("@spscommerce/ds-react"),g=require("@spscommerce/ds-shared"),f=require("@spscommerce/utils");function A(n){if(n&&n.__esModule)return n;const r=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(n){for(const o in n)if(o!=="default"){const s=Object.getOwnPropertyDescriptor(n,o);Object.defineProperty(r,o,s.get?s:{enumerable:!0,get:()=>n[o]})}}return r.default=n,Object.freeze(r)}const e=A(T);function O({isOpen:n,title:r,visibleColumnsHeader:o,hiddenColumnsHeader:s,visibleColumns:u,hiddenColumns:d,manualSort:a=!0,showIcons:i=!0,showCount:v=!0,showFilter:E=!0,showMoveAllLinks:M=!0,onSave:m,onOpen:c,onClose:l,"data-testid":t}){const[p,y]=e.useState(!!n),{t:h}=e.useContext(P.I18nContext),k=P.useChildTestIdAttrBuilder({"data-testid":t}),[C,S]=e.useState({visibleColumns:u,hiddenColumns:d}),w=()=>{y(!1),l==null||l()};return e.useEffect(()=>{p&&(S({visibleColumns:u,hiddenColumns:d}),c==null||c())},[p]),e.useEffect(()=>{y(!!n)},[n]),p?e.createElement(b.SpsModal,{title:r||h("design-system:columnManager.title"),kind:g.ModalKind.GENERAL,size:g.ModalSize.LARGE,"data-testid":t,onClose:w},e.createElement(B.AddToList,{onHeader:o||h("design-system:columnManager.onListHeader"),offHeader:s||h("design-system:columnManager.offListHeader"),onList:C.visibleColumns,offList:C.hiddenColumns,onChange:H=>{S({visibleColumns:H.onList,hiddenColumns:H.offList})},manualSort:a,showIcons:i,showCount:v,showFilter:E,showMoveAllLinks:M,...k("add-to-list")}),e.createElement(b.SpsModalFooter,null,e.createElement(b.SpsButton,{kind:g.ButtonKind.DEFAULT,onClick:()=>{S({visibleColumns:u,hiddenColumns:d}),w()},className:R.sprinkles({mr:"sm"}),...k("cancel-button")},h("design-system:columnManager.cancelButton")),e.createElement(b.SpsButton,{kind:g.ButtonKind.KEY,onClick:()=>{m==null||m(C.visibleColumns,C.hiddenColumns),w()},...k("save-button")},h("design-system:columnManager.saveButton")))):null}P.Metadata.set(O,{name:"Column Manager",props:{isOpen:{type:"boolean",required:!0},title:{type:"string"},visibleColumnsHeader:{type:"string"},hiddenColumnsHeader:{type:"string"},visibleColumns:{type:"ItemProps[]",required:!0},hiddenColumns:{type:"ItemProps[]",required:!0},manualSort:{type:"boolean"},showIcons:{type:"boolean"},showCount:{type:"boolean"},showFilter:{type:"boolean"},showMoveAllLinks:{type:"boolean"},onSave:{type:"(visibleColumns: ItemProps[], hiddenColumns: ItemProps[]) => void"},onClose:{type:"() => void"},onOpen:{type:"() => void"}}});const I=({isOpen:n,visibleColumns:r,hiddenColumns:o,onClose:s,onOpen:u,onSave:d})=>{const[a,i]=e.useState({isOpen:!!n,visibleColumns:r,hiddenColumns:o});e.useEffect(()=>{i(l=>({...l,isOpen:!!n}))},[n]);const v=()=>{i(l=>({...l,isOpen:!0})),u==null||u()},E=()=>{i(l=>({...l,isOpen:!1})),s==null||s()},M=(l,t)=>{i({isOpen:!1,visibleColumns:l,hiddenColumns:t}),d==null||d(l,t)},m=e.useCallback((l,t)=>{i(p=>({...p,visibleColumns:l,hiddenColumns:t}))},[]),c=e.useCallback(l=>{i(t=>({...t,isOpen:l}))},[]);return{visibleColumns:a.visibleColumns,hiddenColumns:a.hiddenColumns,isOpen:a.isOpen,columnManagerProps:{visibleColumns:a.visibleColumns,hiddenColumns:a.hiddenColumns,isOpen:a.isOpen,onClose:E,onSave:M},triggerProps:{onClick:v},setColumns:m,setOpen:c}},L={components:[O],examples:{basic:{label:"Basic Usage",examples:{basic:{react:f.code`
2
+ import { ColumnManager } from "@sps-woodland/column-manager";
3
+ import { SpsButton } from "@spscommerce/ds-react";
4
+
5
+ function Component() {
6
+ const [isOpen, setIsOpen] = React.useState(false);
7
+ const [visibleColumns, setVisibleColumns] = React.useState([
8
+ {id: 1, label: "Phantom Menace"},
9
+ {id: 2, label: "Attack of the Clones"},
10
+ {id: 3, label: "Revenge of the Sith"},
11
+ {id: 4, label: "A New Hope", required: true},
12
+ {id: 5, label: "The Empire Strikes Back"},
13
+ {id: 6, label: "Return of the Jedi"},
14
+ {id: 7, label: "The Force Awakens"}
15
+ ]);
16
+ const [hiddenColumns, setHiddenColumns] = React.useState([
17
+ {id: 8, label: "The Last Jedi"},
18
+ {id: 9, label: "The Rise of Skywalker"}
19
+ ]);
20
+
21
+ function handleSave(visible, hidden) {
22
+ setVisibleColumns(visible);
23
+ setHiddenColumns(hidden);
24
+ setIsOpen(false);
25
+ }
26
+
27
+ function handleClose() {
28
+ setIsOpen(false);
29
+ }
30
+
31
+ function handleOpen() {
32
+ setIsOpen(true);
33
+ }
34
+
35
+ return (
36
+ <div>
37
+ <SpsButton onClick={handleOpen}>Open Column Manager</SpsButton>
38
+ <ColumnManager
39
+ isOpen={isOpen}
40
+ visibleColumns={visibleColumns}
41
+ hiddenColumns={hiddenColumns}
42
+ onHeader="Visible Columns"
43
+ offHeader="Hidden Columns"
44
+ onSave={handleSave}
45
+ onClose={handleClose}
46
+ />
47
+ <br/>
48
+ <div>visibleColumns: {visibleColumns.map(col => col.label).join(", ")}</div>
49
+ <div>hiddenColumns: {hiddenColumns.map(col => col.label).join(", ")}</div>
50
+ </div>
51
+ )
52
+ }
53
+ `}}},hooks:{label:"useColumnManager hook",description:()=>e.createElement(e.Fragment,null,e.createElement("h5",null,"Arguments"),e.createElement("p",null,"The column manager comes with a ",e.createElement("code",null,"useColumnManager")," hook that implements the default behavior. Arguments for this hook include:"),e.createElement("dl",null,e.createElement("dt",null,e.createElement("code",null,"visibleColumns"),": ItemProps[] (required)"),e.createElement("dd",null,"The initial visible columns state"),e.createElement("dt",null,e.createElement("code",null,"hiddenColumns"),": ItemProps[] (required)"),e.createElement("dd",null,"The initial hidden columns state"),e.createElement("dt",null,e.createElement("code",null,"isOpen"),": boolean (optional)"),e.createElement("dd",null,"Whether the column manager is open by default"),e.createElement("dt",null,e.createElement("code",null,"onOpen"),": function (optional)"),e.createElement("dd",null,"Handler that is called when the column manager opens",e.createElement("code",null,"() => void")),e.createElement("dt",null,e.createElement("code",null,"onClose"),": function (optional)"),e.createElement("dd",null,"Handler that is called when the column manager closes",e.createElement("code",null,"() => void")),e.createElement("dt",null,e.createElement("code",null,"onSave"),": function (optional)"),e.createElement("dd",null,"Handler that is called when the column manager saves",e.createElement("code",null,"(visibleColumns: ItemProps[], hiddenColumns: ItemProps[]) => void"))),e.createElement("h5",null,"Return value"),e.createElement("p",null,"The ",e.createElement("code",null,"useColumnManager")," hook returns an object with"," ",e.createElement("code",null,"visibleColumns"),", ",e.createElement("code",null,"hiddenColumns"),", ",e.createElement("code",null,"columnManagerProps"),", ",e.createElement("code",null,"triggerProps")," ,",e.createElement("code",null,"setColumns")," and ",e.createElement("code",null,"setOpen")),e.createElement("p",null,e.createElement("code",null,"triggerProps"),": needs to be spread on the element that triggers the modal."),e.createElement("p",null,e.createElement("code",null,"columnManagerProps"),": needs to be spread on the ",e.createElement("code",null,"ColumnManager")," ","component"),e.createElement("p",null,e.createElement("code",null,"visibleColumns"),": the current state of the visible columns"),e.createElement("p",null,e.createElement("code",null,"hiddenColumns"),": the current state of the hidden columns"),e.createElement("p",null,e.createElement("code",null,"setColumns"),": function that allows programmatically setting the current state of the visible and hidden columns. This function is safe to use in effects."),e.createElement("p",null,e.createElement("code",null,"setOpen"),": function that allows programmatically setting the current isOpen state. This function is safe to use in effects."),e.createElement("p",null,"Please refer to the examples to see its implementation"))},hooksExamples:{label:"Hook Usage",examples:{basic:{description:"Minimal API Reference",react:f.code`
54
+ import { ColumnManager, useColumnManager } from "@sps-woodland/column-manager";
55
+ import { SpsButton } from "@spscommerce/ds-react";
56
+
57
+ function Component() {
58
+ const { visibleColumns, hiddenColumns, columnManagerProps, triggerProps } = useColumnManager({
59
+ visibleColumns: [
60
+ {id: 1, label: "Phantom Menace"},
61
+ {id: 2, label: "Attack of the Clones"},
62
+ {id: 3, label: "Revenge of the Sith"},
63
+ {id: 4, label: "A New Hope", required: true},
64
+ {id: 5, label: "The Empire Strikes Back"},
65
+ {id: 6, label: "Return of the Jedi"},
66
+ {id: 7, label: "The Force Awakens"}
67
+ ],
68
+ hiddenColumns: [
69
+ {id: 8, label: "The Last Jedi"},
70
+ {id: 9, label: "The Rise of Skywalker"}
71
+ ]
72
+ })
73
+
74
+ return (
75
+ <div>
76
+ <SpsButton {...triggerProps}>Open Column Manager</SpsButton>
77
+ <ColumnManager
78
+ {...columnManagerProps}
79
+ onHeader="Visible Columns"
80
+ offHeader="Hidden Columns"
81
+ />
82
+ <br/>
83
+ <div>visibleColumns: {visibleColumns.map(col => col.label).join(", ")}</div>
84
+ <div>hiddenColumns: {hiddenColumns.map(col => col.label).join(", ")}</div>
85
+ </div>
86
+ )
87
+ }
88
+ `},complete:{description:"Complete API Reference",react:f.code`
89
+ import { ColumnManager, useColumnManager } from "@sps-woodland/column-manager";
90
+ import { SpsButton } from "@spscommerce/ds-react";
91
+
92
+ function Component() {
93
+ const initialVisibleColumns = [
94
+ {id: 1, label: "Phantom Menace"},
95
+ {id: 2, label: "Attack of the Clones"},
96
+ {id: 3, label: "Revenge of the Sith"},
97
+ {id: 4, label: "A New Hope", required: true},
98
+ {id: 5, label: "The Empire Strikes Back"},
99
+ {id: 6, label: "Return of the Jedi"},
100
+ {id: 7, label: "The Force Awakens"}
101
+ ];
102
+ const initialHiddenColumns = [
103
+ {id: 8, label: "The Last Jedi"},
104
+ {id: 9, label: "The Rise of Skywalker"}
105
+ ]
106
+ const { visibleColumns, hiddenColumns, columnManagerProps, triggerProps, setColumns } = useColumnManager({
107
+ // this allows controlling the open state externally and providing an initial state
108
+ isOpen: false,
109
+ visibleColumns: initialVisibleColumns,
110
+ hiddenColumns: initialHiddenColumns,
111
+ // a callback when the column manager opens
112
+ onOpen: () => { console.log("onOpen called"); },
113
+ // a callback when the column manager closes
114
+ onClose: () => { console.log("onClose called"); },
115
+ // a callback when the user saves the columns
116
+ onSave: (visible, hidden) => { console.log("onSave called", visible, hidden); },
117
+ });
118
+
119
+ // this allows resetting the columns to the initial state
120
+ const handleReset = () => {
121
+ setColumns(initialVisibleColumns, initialHiddenColumns);
122
+ }
123
+
124
+ return (
125
+ <div>
126
+ <SpsButton {...triggerProps} className={sprinkles({ mr: "sm" })}>Open Column Manager</SpsButton>
127
+ <SpsButton onClick={handleReset}>Reset Columns</SpsButton>
128
+ <ColumnManager
129
+ {...columnManagerProps}
130
+ onHeader="Visible Columns"
131
+ offHeader="Hidden Columns"
132
+ />
133
+ <br/>
134
+ <div>visibleColumns: {visibleColumns.map(col => col.label).join(", ")}</div>
135
+ <div>hiddenColumns: {hiddenColumns.map(col => col.label).join(", ")}</div>
136
+ </div>
137
+ )
138
+ }
139
+ `}}},minimalInterface:{label:"Minimal Interface",examples:{basic:{description:"This is the minimal visual interface for the ColumnManager component",react:f.code`
140
+ import { ColumnManager, useColumnManager } from "@sps-woodland/column-manager";
141
+ import { SpsButton } from "@spscommerce/ds-react";
142
+
143
+ function Component() {
144
+ const { visibleColumns, hiddenColumns, columnManagerProps, triggerProps } = useColumnManager({
145
+ visibleColumns: [
146
+ {id: 1, label: "Phantom Menace"},
147
+ {id: 2, label: "Attack of the Clones"},
148
+ {id: 3, label: "Revenge of the Sith"},
149
+ {id: 4, label: "A New Hope", required: true},
150
+ {id: 5, label: "The Empire Strikes Back"},
151
+ {id: 6, label: "Return of the Jedi"},
152
+ {id: 7, label: "The Force Awakens"}
153
+ ],
154
+ hiddenColumns: [
155
+ {id: 8, label: "The Last Jedi"},
156
+ {id: 9, label: "The Rise of Skywalker"}
157
+ ]
158
+ })
159
+
160
+ return (
161
+ <div>
162
+ <SpsButton {...triggerProps}>Open Column Manager</SpsButton>
163
+ <ColumnManager
164
+ {...columnManagerProps}
165
+ onHeader="Visible Columns"
166
+ offHeader="Hidden Columns"
167
+ showMoveAllLinks={false}
168
+ showFilter={false}
169
+ showCount={false}
170
+ showIcons={false}
171
+ manualSort={false}
172
+ />
173
+ <br/>
174
+ <div>visibleColumns: {visibleColumns.map(col => col.label).join(", ")}</div>
175
+ <div>hiddenColumns: {hiddenColumns.map(col => col.label).join(", ")}</div>
176
+ </div>
177
+ )
178
+ }
179
+ `}}}}},q={"Column Manager":L};exports.ColumnManager=O;exports.MANIFEST=q;exports.useColumnManager=I;
package/lib/index.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ export * from "./column-manager/ColumnManager";
2
+ export * from "./column-manager/useColumnManager";
3
+ export * from "./manifest";
@@ -0,0 +1,356 @@
1
+ import * as e from "react";
2
+ import { Metadata as O, I18nContext as T, useChildTestIdAttrBuilder as B } from "@sps-woodland/core";
3
+ import { AddToList as R } from "@sps-woodland/add-to-list";
4
+ import { sprinkles as A } from "@sps-woodland/tokens";
5
+ import { SpsModal as I, SpsModalFooter as L, SpsButton as H } from "@spscommerce/ds-react";
6
+ import { ModalKind as x, ModalSize as F, ButtonKind as P } from "@spscommerce/ds-shared";
7
+ import { code as h } from "@spscommerce/utils";
8
+ function y({
9
+ isOpen: s,
10
+ title: C,
11
+ visibleColumnsHeader: b,
12
+ hiddenColumnsHeader: r,
13
+ visibleColumns: a,
14
+ hiddenColumns: i,
15
+ manualSort: t = !0,
16
+ showIcons: o = !0,
17
+ showCount: f = !0,
18
+ showFilter: g = !0,
19
+ showMoveAllLinks: v = !0,
20
+ onSave: m,
21
+ onOpen: u,
22
+ onClose: n,
23
+ "data-testid": l
24
+ }) {
25
+ const [d, S] = e.useState(!!s), { t: c } = e.useContext(T), E = B({ "data-testid": l }), [p, M] = e.useState({
26
+ visibleColumns: a,
27
+ hiddenColumns: i
28
+ }), k = () => {
29
+ S(!1), n == null || n();
30
+ };
31
+ return e.useEffect(() => {
32
+ d && (M({ visibleColumns: a, hiddenColumns: i }), u == null || u());
33
+ }, [d]), e.useEffect(() => {
34
+ S(!!s);
35
+ }, [s]), d ? /* @__PURE__ */ e.createElement(I, {
36
+ title: C || c("design-system:columnManager.title"),
37
+ kind: x.GENERAL,
38
+ size: F.LARGE,
39
+ "data-testid": l,
40
+ onClose: k
41
+ }, /* @__PURE__ */ e.createElement(R, {
42
+ onHeader: b || c("design-system:columnManager.onListHeader"),
43
+ offHeader: r || c("design-system:columnManager.offListHeader"),
44
+ onList: p.visibleColumns,
45
+ offList: p.hiddenColumns,
46
+ onChange: (w) => {
47
+ M({ visibleColumns: w.onList, hiddenColumns: w.offList });
48
+ },
49
+ manualSort: t,
50
+ showIcons: o,
51
+ showCount: f,
52
+ showFilter: g,
53
+ showMoveAllLinks: v,
54
+ ...E("add-to-list")
55
+ }), /* @__PURE__ */ e.createElement(L, null, /* @__PURE__ */ e.createElement(H, {
56
+ kind: P.DEFAULT,
57
+ onClick: () => {
58
+ M({ visibleColumns: a, hiddenColumns: i }), k();
59
+ },
60
+ className: A({ mr: "sm" }),
61
+ ...E("cancel-button")
62
+ }, c("design-system:columnManager.cancelButton")), /* @__PURE__ */ e.createElement(H, {
63
+ kind: P.KEY,
64
+ onClick: () => {
65
+ m == null || m(p.visibleColumns, p.hiddenColumns), k();
66
+ },
67
+ ...E("save-button")
68
+ }, c("design-system:columnManager.saveButton")))) : null;
69
+ }
70
+ O.set(y, {
71
+ name: "Column Manager",
72
+ props: {
73
+ isOpen: { type: "boolean", required: !0 },
74
+ title: { type: "string" },
75
+ visibleColumnsHeader: { type: "string" },
76
+ hiddenColumnsHeader: { type: "string" },
77
+ visibleColumns: { type: "ItemProps[]", required: !0 },
78
+ hiddenColumns: { type: "ItemProps[]", required: !0 },
79
+ manualSort: { type: "boolean" },
80
+ showIcons: { type: "boolean" },
81
+ showCount: { type: "boolean" },
82
+ showFilter: { type: "boolean" },
83
+ showMoveAllLinks: { type: "boolean" },
84
+ onSave: { type: "(visibleColumns: ItemProps[], hiddenColumns: ItemProps[]) => void" },
85
+ onClose: { type: "() => void" },
86
+ onOpen: { type: "() => void" }
87
+ }
88
+ });
89
+ const z = ({
90
+ isOpen: s,
91
+ visibleColumns: C,
92
+ hiddenColumns: b,
93
+ onClose: r,
94
+ onOpen: a,
95
+ onSave: i
96
+ }) => {
97
+ const [t, o] = e.useState({
98
+ isOpen: !!s,
99
+ visibleColumns: C,
100
+ hiddenColumns: b
101
+ });
102
+ e.useEffect(() => {
103
+ o((n) => ({ ...n, isOpen: !!s }));
104
+ }, [s]);
105
+ const f = () => {
106
+ o((n) => ({ ...n, isOpen: !0 })), a == null || a();
107
+ }, g = () => {
108
+ o((n) => ({ ...n, isOpen: !1 })), r == null || r();
109
+ }, v = (n, l) => {
110
+ o({ isOpen: !1, visibleColumns: n, hiddenColumns: l }), i == null || i(n, l);
111
+ }, m = e.useCallback((n, l) => {
112
+ o((d) => ({ ...d, visibleColumns: n, hiddenColumns: l }));
113
+ }, []), u = e.useCallback((n) => {
114
+ o((l) => ({ ...l, isOpen: n }));
115
+ }, []);
116
+ return {
117
+ visibleColumns: t.visibleColumns,
118
+ hiddenColumns: t.hiddenColumns,
119
+ isOpen: t.isOpen,
120
+ columnManagerProps: {
121
+ visibleColumns: t.visibleColumns,
122
+ hiddenColumns: t.hiddenColumns,
123
+ isOpen: t.isOpen,
124
+ onClose: g,
125
+ onSave: v
126
+ },
127
+ triggerProps: {
128
+ onClick: f
129
+ },
130
+ setColumns: m,
131
+ setOpen: u
132
+ };
133
+ }, j = {
134
+ components: [y],
135
+ examples: {
136
+ basic: {
137
+ label: "Basic Usage",
138
+ examples: {
139
+ basic: {
140
+ react: h`
141
+ import { ColumnManager } from "@sps-woodland/column-manager";
142
+ import { SpsButton } from "@spscommerce/ds-react";
143
+
144
+ function Component() {
145
+ const [isOpen, setIsOpen] = React.useState(false);
146
+ const [visibleColumns, setVisibleColumns] = React.useState([
147
+ {id: 1, label: "Phantom Menace"},
148
+ {id: 2, label: "Attack of the Clones"},
149
+ {id: 3, label: "Revenge of the Sith"},
150
+ {id: 4, label: "A New Hope", required: true},
151
+ {id: 5, label: "The Empire Strikes Back"},
152
+ {id: 6, label: "Return of the Jedi"},
153
+ {id: 7, label: "The Force Awakens"}
154
+ ]);
155
+ const [hiddenColumns, setHiddenColumns] = React.useState([
156
+ {id: 8, label: "The Last Jedi"},
157
+ {id: 9, label: "The Rise of Skywalker"}
158
+ ]);
159
+
160
+ function handleSave(visible, hidden) {
161
+ setVisibleColumns(visible);
162
+ setHiddenColumns(hidden);
163
+ setIsOpen(false);
164
+ }
165
+
166
+ function handleClose() {
167
+ setIsOpen(false);
168
+ }
169
+
170
+ function handleOpen() {
171
+ setIsOpen(true);
172
+ }
173
+
174
+ return (
175
+ <div>
176
+ <SpsButton onClick={handleOpen}>Open Column Manager</SpsButton>
177
+ <ColumnManager
178
+ isOpen={isOpen}
179
+ visibleColumns={visibleColumns}
180
+ hiddenColumns={hiddenColumns}
181
+ onHeader="Visible Columns"
182
+ offHeader="Hidden Columns"
183
+ onSave={handleSave}
184
+ onClose={handleClose}
185
+ />
186
+ <br/>
187
+ <div>visibleColumns: {visibleColumns.map(col => col.label).join(", ")}</div>
188
+ <div>hiddenColumns: {hiddenColumns.map(col => col.label).join(", ")}</div>
189
+ </div>
190
+ )
191
+ }
192
+ `
193
+ }
194
+ }
195
+ },
196
+ hooks: {
197
+ label: "useColumnManager hook",
198
+ description: () => /* @__PURE__ */ e.createElement(e.Fragment, null, /* @__PURE__ */ e.createElement("h5", null, "Arguments"), /* @__PURE__ */ e.createElement("p", null, "The column manager comes with a ", /* @__PURE__ */ e.createElement("code", null, "useColumnManager"), " hook that implements the default behavior. Arguments for this hook include:"), /* @__PURE__ */ e.createElement("dl", null, /* @__PURE__ */ e.createElement("dt", null, /* @__PURE__ */ e.createElement("code", null, "visibleColumns"), ": ItemProps[] (required)"), /* @__PURE__ */ e.createElement("dd", null, "The initial visible columns state"), /* @__PURE__ */ e.createElement("dt", null, /* @__PURE__ */ e.createElement("code", null, "hiddenColumns"), ": ItemProps[] (required)"), /* @__PURE__ */ e.createElement("dd", null, "The initial hidden columns state"), /* @__PURE__ */ e.createElement("dt", null, /* @__PURE__ */ e.createElement("code", null, "isOpen"), ": boolean (optional)"), /* @__PURE__ */ e.createElement("dd", null, "Whether the column manager is open by default"), /* @__PURE__ */ e.createElement("dt", null, /* @__PURE__ */ e.createElement("code", null, "onOpen"), ": function (optional)"), /* @__PURE__ */ e.createElement("dd", null, "Handler that is called when the column manager opens", /* @__PURE__ */ e.createElement("code", null, "() => void")), /* @__PURE__ */ e.createElement("dt", null, /* @__PURE__ */ e.createElement("code", null, "onClose"), ": function (optional)"), /* @__PURE__ */ e.createElement("dd", null, "Handler that is called when the column manager closes", /* @__PURE__ */ e.createElement("code", null, "() => void")), /* @__PURE__ */ e.createElement("dt", null, /* @__PURE__ */ e.createElement("code", null, "onSave"), ": function (optional)"), /* @__PURE__ */ e.createElement("dd", null, "Handler that is called when the column manager saves", /* @__PURE__ */ e.createElement("code", null, "(visibleColumns: ItemProps[], hiddenColumns: ItemProps[]) => void"))), /* @__PURE__ */ e.createElement("h5", null, "Return value"), /* @__PURE__ */ e.createElement("p", null, "The ", /* @__PURE__ */ e.createElement("code", null, "useColumnManager"), " hook returns an object with", " ", /* @__PURE__ */ e.createElement("code", null, "visibleColumns"), ", ", /* @__PURE__ */ e.createElement("code", null, "hiddenColumns"), ", ", /* @__PURE__ */ e.createElement("code", null, "columnManagerProps"), ", ", /* @__PURE__ */ e.createElement("code", null, "triggerProps"), " ,", /* @__PURE__ */ e.createElement("code", null, "setColumns"), " and ", /* @__PURE__ */ e.createElement("code", null, "setOpen")), /* @__PURE__ */ e.createElement("p", null, /* @__PURE__ */ e.createElement("code", null, "triggerProps"), ": needs to be spread on the element that triggers the modal."), /* @__PURE__ */ e.createElement("p", null, /* @__PURE__ */ e.createElement("code", null, "columnManagerProps"), ": needs to be spread on the ", /* @__PURE__ */ e.createElement("code", null, "ColumnManager"), " ", "component"), /* @__PURE__ */ e.createElement("p", null, /* @__PURE__ */ e.createElement("code", null, "visibleColumns"), ": the current state of the visible columns"), /* @__PURE__ */ e.createElement("p", null, /* @__PURE__ */ e.createElement("code", null, "hiddenColumns"), ": the current state of the hidden columns"), /* @__PURE__ */ e.createElement("p", null, /* @__PURE__ */ e.createElement("code", null, "setColumns"), ": function that allows programmatically setting the current state of the visible and hidden columns. This function is safe to use in effects."), /* @__PURE__ */ e.createElement("p", null, /* @__PURE__ */ e.createElement("code", null, "setOpen"), ": function that allows programmatically setting the current isOpen state. This function is safe to use in effects."), /* @__PURE__ */ e.createElement("p", null, "Please refer to the examples to see its implementation"))
199
+ },
200
+ hooksExamples: {
201
+ label: "Hook Usage",
202
+ examples: {
203
+ basic: {
204
+ description: "Minimal API Reference",
205
+ react: h`
206
+ import { ColumnManager, useColumnManager } from "@sps-woodland/column-manager";
207
+ import { SpsButton } from "@spscommerce/ds-react";
208
+
209
+ function Component() {
210
+ const { visibleColumns, hiddenColumns, columnManagerProps, triggerProps } = useColumnManager({
211
+ visibleColumns: [
212
+ {id: 1, label: "Phantom Menace"},
213
+ {id: 2, label: "Attack of the Clones"},
214
+ {id: 3, label: "Revenge of the Sith"},
215
+ {id: 4, label: "A New Hope", required: true},
216
+ {id: 5, label: "The Empire Strikes Back"},
217
+ {id: 6, label: "Return of the Jedi"},
218
+ {id: 7, label: "The Force Awakens"}
219
+ ],
220
+ hiddenColumns: [
221
+ {id: 8, label: "The Last Jedi"},
222
+ {id: 9, label: "The Rise of Skywalker"}
223
+ ]
224
+ })
225
+
226
+ return (
227
+ <div>
228
+ <SpsButton {...triggerProps}>Open Column Manager</SpsButton>
229
+ <ColumnManager
230
+ {...columnManagerProps}
231
+ onHeader="Visible Columns"
232
+ offHeader="Hidden Columns"
233
+ />
234
+ <br/>
235
+ <div>visibleColumns: {visibleColumns.map(col => col.label).join(", ")}</div>
236
+ <div>hiddenColumns: {hiddenColumns.map(col => col.label).join(", ")}</div>
237
+ </div>
238
+ )
239
+ }
240
+ `
241
+ },
242
+ complete: {
243
+ description: "Complete API Reference",
244
+ react: h`
245
+ import { ColumnManager, useColumnManager } from "@sps-woodland/column-manager";
246
+ import { SpsButton } from "@spscommerce/ds-react";
247
+
248
+ function Component() {
249
+ const initialVisibleColumns = [
250
+ {id: 1, label: "Phantom Menace"},
251
+ {id: 2, label: "Attack of the Clones"},
252
+ {id: 3, label: "Revenge of the Sith"},
253
+ {id: 4, label: "A New Hope", required: true},
254
+ {id: 5, label: "The Empire Strikes Back"},
255
+ {id: 6, label: "Return of the Jedi"},
256
+ {id: 7, label: "The Force Awakens"}
257
+ ];
258
+ const initialHiddenColumns = [
259
+ {id: 8, label: "The Last Jedi"},
260
+ {id: 9, label: "The Rise of Skywalker"}
261
+ ]
262
+ const { visibleColumns, hiddenColumns, columnManagerProps, triggerProps, setColumns } = useColumnManager({
263
+ // this allows controlling the open state externally and providing an initial state
264
+ isOpen: false,
265
+ visibleColumns: initialVisibleColumns,
266
+ hiddenColumns: initialHiddenColumns,
267
+ // a callback when the column manager opens
268
+ onOpen: () => { console.log("onOpen called"); },
269
+ // a callback when the column manager closes
270
+ onClose: () => { console.log("onClose called"); },
271
+ // a callback when the user saves the columns
272
+ onSave: (visible, hidden) => { console.log("onSave called", visible, hidden); },
273
+ });
274
+
275
+ // this allows resetting the columns to the initial state
276
+ const handleReset = () => {
277
+ setColumns(initialVisibleColumns, initialHiddenColumns);
278
+ }
279
+
280
+ return (
281
+ <div>
282
+ <SpsButton {...triggerProps} className={sprinkles({ mr: "sm" })}>Open Column Manager</SpsButton>
283
+ <SpsButton onClick={handleReset}>Reset Columns</SpsButton>
284
+ <ColumnManager
285
+ {...columnManagerProps}
286
+ onHeader="Visible Columns"
287
+ offHeader="Hidden Columns"
288
+ />
289
+ <br/>
290
+ <div>visibleColumns: {visibleColumns.map(col => col.label).join(", ")}</div>
291
+ <div>hiddenColumns: {hiddenColumns.map(col => col.label).join(", ")}</div>
292
+ </div>
293
+ )
294
+ }
295
+ `
296
+ }
297
+ }
298
+ },
299
+ minimalInterface: {
300
+ label: "Minimal Interface",
301
+ examples: {
302
+ basic: {
303
+ description: "This is the minimal visual interface for the ColumnManager component",
304
+ react: h`
305
+ import { ColumnManager, useColumnManager } from "@sps-woodland/column-manager";
306
+ import { SpsButton } from "@spscommerce/ds-react";
307
+
308
+ function Component() {
309
+ const { visibleColumns, hiddenColumns, columnManagerProps, triggerProps } = useColumnManager({
310
+ visibleColumns: [
311
+ {id: 1, label: "Phantom Menace"},
312
+ {id: 2, label: "Attack of the Clones"},
313
+ {id: 3, label: "Revenge of the Sith"},
314
+ {id: 4, label: "A New Hope", required: true},
315
+ {id: 5, label: "The Empire Strikes Back"},
316
+ {id: 6, label: "Return of the Jedi"},
317
+ {id: 7, label: "The Force Awakens"}
318
+ ],
319
+ hiddenColumns: [
320
+ {id: 8, label: "The Last Jedi"},
321
+ {id: 9, label: "The Rise of Skywalker"}
322
+ ]
323
+ })
324
+
325
+ return (
326
+ <div>
327
+ <SpsButton {...triggerProps}>Open Column Manager</SpsButton>
328
+ <ColumnManager
329
+ {...columnManagerProps}
330
+ onHeader="Visible Columns"
331
+ offHeader="Hidden Columns"
332
+ showMoveAllLinks={false}
333
+ showFilter={false}
334
+ showCount={false}
335
+ showIcons={false}
336
+ manualSort={false}
337
+ />
338
+ <br/>
339
+ <div>visibleColumns: {visibleColumns.map(col => col.label).join(", ")}</div>
340
+ <div>hiddenColumns: {hiddenColumns.map(col => col.label).join(", ")}</div>
341
+ </div>
342
+ )
343
+ }
344
+ `
345
+ }
346
+ }
347
+ }
348
+ }
349
+ }, G = {
350
+ "Column Manager": j
351
+ };
352
+ export {
353
+ y as ColumnManager,
354
+ G as MANIFEST,
355
+ z as useColumnManager
356
+ };
@@ -0,0 +1,2 @@
1
+ import type { ComponentManifest } from "@sps-woodland/core";
2
+ export declare const MANIFEST: ComponentManifest;
package/package.json ADDED
@@ -0,0 +1,50 @@
1
+ {
2
+ "name": "@sps-woodland/column-manager",
3
+ "description": "SPS Woodland Design System column manager component",
4
+ "version": "7.5.0",
5
+ "author": "SPS Commerce",
6
+ "license": "UNLICENSED",
7
+ "repository": "https://github.com/SPSCommerce/woodland/tree/main/packages/@sps-woodland/column-manager",
8
+ "homepage": "https://github.com/SPSCommerce/woodland/tree/master/packages/@sps-woodland/column-manager#readme",
9
+ "main": "./lib/index.es.js",
10
+ "module": "./lib/index.es.js",
11
+ "types": "./lib/index.d.ts",
12
+ "publishConfig": {
13
+ "access": "public"
14
+ },
15
+ "peerDependencies": {
16
+ "@sps-woodland/core": "7.5.0",
17
+ "@sps-woodland/add-to-list": "7.5.0",
18
+ "@sps-woodland/tokens": "7.5.0",
19
+ "@spscommerce/utils": "^6.12.1",
20
+ "@vanilla-extract/css-utils": "^0.1.3",
21
+ "@spscommerce/ds-react": "7.5.0",
22
+ "@spscommerce/ds-shared": "7.5.0",
23
+ "react": "^16.9.0",
24
+ "react-dom": "^16.9.0"
25
+ },
26
+ "devDependencies": {
27
+ "@sps-woodland/core": "7.5.0",
28
+ "@sps-woodland/add-to-list": "7.5.0",
29
+ "@sps-woodland/tokens": "7.5.0",
30
+ "@spscommerce/utils": "^6.12.1",
31
+ "@vanilla-extract/css": "^1.9.1",
32
+ "@vanilla-extract/recipes": "^0.2.5",
33
+ "@vanilla-extract/css-utils": "^0.1.3",
34
+ "@spscommerce/ds-react": "7.5.0",
35
+ "@spscommerce/ds-shared": "7.5.0",
36
+ "react": "^16.9.0",
37
+ "react-dom": "^16.9.0"
38
+ },
39
+ "dependencies": {
40
+ "nanoid": "^3.3.4"
41
+ },
42
+ "scripts": {
43
+ "build": "pnpm run build:js && pnpm run build:types",
44
+ "build:js": "vite build",
45
+ "build:types": "tsc --emitDeclarationOnly --declaration --declarationDir lib",
46
+ "watch": "vite build --watch",
47
+ "clean": "git clean -fdX",
48
+ "pub": "node ../../../scripts/publish-package.js"
49
+ }
50
+ }
package/vite.config.js ADDED
@@ -0,0 +1,21 @@
1
+ import path from "path";
2
+ import { vanillaExtractPlugin } from "@vanilla-extract/vite-plugin";
3
+ import { defineConfig } from "vite";
4
+
5
+ import pkg from "./package.json";
6
+
7
+ export default defineConfig({
8
+ plugins: [vanillaExtractPlugin()],
9
+ build: {
10
+ lib: {
11
+ entry: path.resolve(__dirname, "src/index.ts"),
12
+ formats: ["es", "cjs"],
13
+ fileName: (format) => `index.${format}.js`,
14
+ },
15
+ outDir: path.resolve(__dirname, "./lib"),
16
+ emptyOutDir: false,
17
+ rollupOptions: {
18
+ external: pkg.peerDependencies ? Object.keys(pkg.peerDependencies) : [],
19
+ },
20
+ },
21
+ });