@sps-woodland/sorting-header 7.17.13 → 7.19.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.
@@ -1,7 +1,7 @@
1
- import * as a from "react";
2
- import { Metadata as D, cl as h, SortDirection as w, selectChildren as A, modChildren as P } from "@sps-woodland/core";
3
- import { lockToAnimationFrames as V, code as T } from "@spscommerce/utils";
4
- function _(e, n, r) {
1
+ import * as s from "react";
2
+ import { Metadata as I, cl as w, SortDirection as S, selectChildren as H, modChildren as O } from "@sps-woodland/core";
3
+ import { lockToAnimationFrames as A, code as P } from "@spscommerce/utils";
4
+ function V(e, n, r) {
5
5
  return n in e ? Object.defineProperty(e, n, {
6
6
  value: r,
7
7
  enumerable: !0,
@@ -9,7 +9,7 @@ function _(e, n, r) {
9
9
  writable: !0
10
10
  }) : e[n] = r, e;
11
11
  }
12
- function b(e, n) {
12
+ function N(e, n) {
13
13
  var r = Object.keys(e);
14
14
  if (Object.getOwnPropertySymbols) {
15
15
  var t = Object.getOwnPropertySymbols(e);
@@ -19,87 +19,87 @@ function b(e, n) {
19
19
  }
20
20
  return r;
21
21
  }
22
- function R(e) {
22
+ function b(e) {
23
23
  for (var n = 1; n < arguments.length; n++) {
24
24
  var r = arguments[n] != null ? arguments[n] : {};
25
- n % 2 ? b(Object(r), !0).forEach(function(t) {
26
- _(e, t, r[t]);
27
- }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(r)) : b(Object(r)).forEach(function(t) {
25
+ n % 2 ? N(Object(r), !0).forEach(function(t) {
26
+ V(e, t, r[t]);
27
+ }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(r)) : N(Object(r)).forEach(function(t) {
28
28
  Object.defineProperty(e, t, Object.getOwnPropertyDescriptor(r, t));
29
29
  });
30
30
  }
31
31
  return e;
32
32
  }
33
- var K = (e, n, r) => {
33
+ var T = (e, n, r) => {
34
34
  for (var t of Object.keys(e)) {
35
35
  var i;
36
36
  if (e[t] !== ((i = n[t]) !== null && i !== void 0 ? i : r[t]))
37
37
  return !1;
38
38
  }
39
39
  return !0;
40
- }, v = (e) => (n) => {
41
- var r = e.defaultClassName, t = R(R({}, e.defaultVariants), n);
40
+ }, C = (e) => (n) => {
41
+ var r = e.defaultClassName, t = b(b({}, e.defaultVariants), n);
42
42
  for (var i in t) {
43
- var l, p = (l = t[i]) !== null && l !== void 0 ? l : e.defaultVariants[i];
44
- if (p != null) {
45
- var u = p;
43
+ var l, m = (l = t[i]) !== null && l !== void 0 ? l : e.defaultVariants[i];
44
+ if (m != null) {
45
+ var u = m;
46
46
  typeof u == "boolean" && (u = u === !0 ? "true" : "false");
47
47
  var d = e.variantClassNames[i][u];
48
48
  d && (r += " " + d);
49
49
  }
50
50
  }
51
- for (var [m, s] of e.compoundVariants)
52
- K(m, t, e.defaultVariants) && (r += " " + s);
51
+ for (var [p, a] of e.compoundVariants)
52
+ T(p, t, e.defaultVariants) && (r += " " + a);
53
53
  return r;
54
- }, k = v({ defaultClassName: "_7ljhcs0", variantClassNames: { up: { true: "_7ljhcs1" }, down: { true: "_7ljhcs2" } }, defaultVariants: {}, compoundVariants: [] });
55
- var j = v({ defaultClassName: "_1crs4gl0", variantClassNames: { disabled: { true: "_1crs4gl1" }, active: { true: "_1crs4gl2" } }, defaultVariants: { disabled: !1, active: !1 }, compoundVariants: [] });
56
- function E({
54
+ }, K = C({ defaultClassName: "pkg_sps-woodland_sorting-header__version_7_19_0__hash_7ljhcs0", variantClassNames: { up: { true: "pkg_sps-woodland_sorting-header__version_7_19_0__hash_7ljhcs1" }, down: { true: "pkg_sps-woodland_sorting-header__version_7_19_0__hash_7ljhcs2" } }, defaultVariants: {}, compoundVariants: [] });
55
+ var j = C({ defaultClassName: "pkg_sps-woodland_sorting-header__version_7_19_0__hash_1crs4gl0", variantClassNames: { disabled: { true: "pkg_sps-woodland_sorting-header__version_7_19_0__hash_1crs4gl1" }, active: { true: "pkg_sps-woodland_sorting-header__version_7_19_0__hash_1crs4gl2" } }, defaultVariants: { disabled: !1, active: !1 }, compoundVariants: [] });
56
+ function v({
57
57
  className: e,
58
58
  sortKey: n,
59
59
  sort: r,
60
60
  sortDisabled: t,
61
61
  onSortChange: i,
62
62
  onClick: l,
63
- children: p,
63
+ children: m,
64
64
  style: u,
65
65
  widthPx: d,
66
- widthRem: m,
67
- ...s
66
+ widthRem: p,
67
+ ...a
68
68
  }) {
69
- const c = a.useMemo(() => {
70
- const S = !!n && !t && Array.isArray(r) && r.find((o) => o.key === n);
71
- return S ? S.direction : void 0;
69
+ const c = s.useMemo(() => {
70
+ const f = !!n && !t && Array.isArray(r) && r.find((o) => o.key === n);
71
+ return f ? f.direction : void 0;
72
72
  }, [
73
73
  r,
74
74
  n,
75
75
  t
76
- ]), C = d ? d / 16 : m, g = C ? { ...u, width: `${C}rem` } : u;
77
- return /* @__PURE__ */ a.createElement(
76
+ ]), g = d ? d / 16 : p, y = g ? { ...u, width: `${g}rem` } : u;
77
+ return /* @__PURE__ */ s.createElement(
78
78
  "div",
79
79
  {
80
- className: h(
80
+ className: w(
81
81
  e,
82
82
  j({ disabled: t, active: !!c }),
83
- c && k({
84
- up: c === w.ASCENDING,
85
- down: c === w.DESCENDING
83
+ c && K({
84
+ up: c === S.ASCENDING,
85
+ down: c === S.DESCENDING
86
86
  })
87
87
  ),
88
- onClick: (S) => {
88
+ onClick: (f) => {
89
89
  n && !t && i && i([
90
90
  {
91
91
  key: n,
92
- direction: c === w.ASCENDING ? w.DESCENDING : w.ASCENDING
92
+ direction: c === S.ASCENDING ? S.DESCENDING : S.ASCENDING
93
93
  }
94
- ]), l && l(S);
94
+ ]), l && l(f);
95
95
  },
96
- style: g,
97
- ...s
96
+ style: y,
97
+ ...a
98
98
  },
99
- p
99
+ m
100
100
  );
101
101
  }
102
- D.set(E, {
102
+ I.set(v, {
103
103
  name: "Sorting Header Cell",
104
104
  props: {
105
105
  sortKey: { type: "string" },
@@ -110,8 +110,8 @@ D.set(E, {
110
110
  widthRem: { type: "number" }
111
111
  }
112
112
  });
113
- var I = v({ defaultClassName: "sk81640", variantClassNames: { pinned: { true: "sk81641", false: "sk81642" } }, defaultVariants: { pinned: !1 }, compoundVariants: [] });
114
- function H({
113
+ var R = C({ defaultClassName: "pkg_sps-woodland_sorting-header__version_7_19_0__hash_sk81640", variantClassNames: { pinned: { true: "pkg_sps-woodland_sorting-header__version_7_19_0__hash_sk81641", false: "pkg_sps-woodland_sorting-header__version_7_19_0__hash_sk81642" } }, defaultVariants: { pinned: !1 }, compoundVariants: [] });
114
+ function k({
115
115
  sort: e,
116
116
  onSortChange: n,
117
117
  children: r,
@@ -119,73 +119,73 @@ function H({
119
119
  pinSortingHeader: i = !1,
120
120
  ...l
121
121
  }) {
122
- const [p, u] = a.useState(!1), d = a.useRef(null), m = a.useRef(null), s = a.useRef({
122
+ const [m, u] = s.useState(!1), d = s.useRef(null), p = s.useRef(null), a = s.useRef({
123
123
  height: "",
124
124
  width: "",
125
125
  unpinAtTop: 0,
126
126
  unpinAtBottom: 0,
127
127
  cellWidths: []
128
- }), c = a.useCallback(() => {
128
+ }), c = s.useCallback(() => {
129
129
  var o;
130
130
  if (i && d.current) {
131
- const y = (o = d.current.parentElement) == null ? void 0 : o.getBoundingClientRect();
132
- if (y) {
133
- const f = d.current.getBoundingClientRect();
134
- s.current.height = `${f.height}px`, s.current.width = `${f.width}px`, s.current.unpinAtBottom = y.bottom + window.scrollY - f.height * 2, s.current.unpinAtTop = f.top + window.scrollY - f.height, s.current.cellWidths = [], d.current.childNodes.forEach((N, O) => {
135
- N instanceof HTMLElement && (s.current.cellWidths[O] = `${N.getBoundingClientRect().width}px`);
131
+ const h = (o = d.current.parentElement) == null ? void 0 : o.getBoundingClientRect();
132
+ if (h) {
133
+ const _ = d.current.getBoundingClientRect();
134
+ a.current.height = `${_.height}px`, a.current.width = `${_.width}px`, a.current.unpinAtBottom = h.bottom + window.scrollY - _.height * 2, a.current.unpinAtTop = _.top + window.scrollY - _.height, a.current.cellWidths = [], d.current.childNodes.forEach((E, D) => {
135
+ E instanceof HTMLElement && (a.current.cellWidths[D] = `${E.getBoundingClientRect().width}px`);
136
136
  });
137
137
  }
138
138
  }
139
- }, [i]), C = a.useCallback(() => {
140
- m.current && (m.current.style.width = s.current.width, m.current.style.height = s.current.height, m.current.childNodes.forEach((o, y) => {
141
- o instanceof HTMLElement && (o.style.width = s.current.cellWidths[y] || "");
139
+ }, [i]), g = s.useCallback(() => {
140
+ p.current && (p.current.style.width = a.current.width, p.current.style.height = a.current.height, p.current.childNodes.forEach((o, h) => {
141
+ o instanceof HTMLElement && (o.style.width = a.current.cellWidths[h] || "");
142
142
  }));
143
143
  }, []);
144
- a.useLayoutEffect(() => {
144
+ s.useLayoutEffect(() => {
145
145
  c();
146
- }), a.useLayoutEffect(() => {
146
+ }), s.useLayoutEffect(() => {
147
147
  let o;
148
- return i && (o = V(() => {
148
+ return i && (o = A(() => {
149
149
  c();
150
- const { unpinAtTop: y, unpinAtBottom: f } = s.current;
151
- y && f && (window.scrollY >= y && window.scrollY <= f ? u(!0) : u(!1));
150
+ const { unpinAtTop: h, unpinAtBottom: _ } = a.current;
151
+ h && _ && (window.scrollY >= h && window.scrollY <= _ ? u(!0) : u(!1));
152
152
  }), window.addEventListener("scroll", o), o()), () => {
153
153
  o && window.removeEventListener("scroll", o);
154
154
  };
155
- }, [i, c]), a.useLayoutEffect(() => {
155
+ }, [i, c]), s.useLayoutEffect(() => {
156
156
  let o;
157
- return p && (o = () => {
158
- c(), C();
157
+ return m && (o = () => {
158
+ c(), g();
159
159
  }, window.addEventListener("resize", o), o()), () => {
160
160
  o && window.removeEventListener("resize", o);
161
161
  };
162
162
  }, [
163
- p,
163
+ m,
164
164
  c,
165
- C
165
+ g
166
166
  ]);
167
- const [g] = A(r, [{ type: E }]), S = P(g, () => [{ sort: e, onSortChange: n }]);
168
- return /* @__PURE__ */ a.createElement(a.Fragment, null, /* @__PURE__ */ a.createElement(
167
+ const [y] = H(r, [{ type: v }]), f = O(y, () => [{ sort: e, onSortChange: n }]);
168
+ return /* @__PURE__ */ s.createElement(s.Fragment, null, /* @__PURE__ */ s.createElement(
169
169
  "div",
170
170
  {
171
171
  ref: d,
172
- className: h(t, I({ pinned: !1 })),
172
+ className: w(t, R({ pinned: !1 })),
173
173
  ...l
174
174
  },
175
- S
176
- ), p && /* @__PURE__ */ a.createElement(
175
+ f
176
+ ), m && /* @__PURE__ */ s.createElement(
177
177
  "div",
178
178
  {
179
- ref: m,
180
- className: h(t, I({ pinned: !0 })),
179
+ ref: p,
180
+ className: w(t, R({ pinned: !0 })),
181
181
  ...l,
182
182
  id: l.id ? `pinned-${l.id}` : void 0,
183
183
  "data-testid": l["data-testid"] ? `pinned-${l["data-testid"]}` : void 0
184
184
  },
185
- S
185
+ f
186
186
  ));
187
187
  }
188
- D.set(H, {
188
+ I.set(k, {
189
189
  name: "Sorting Header",
190
190
  props: {
191
191
  sort: { type: "SortedColumn[]" },
@@ -193,13 +193,13 @@ D.set(H, {
193
193
  }
194
194
  });
195
195
  const L = {
196
- components: [H, E],
196
+ components: [k, v],
197
197
  examples: {
198
198
  basic: {
199
199
  label: "Sorting Header",
200
200
  examples: {
201
201
  basic: {
202
- react: T`
202
+ react: P`
203
203
  import { SortingHeader, SortingHeaderCell } from "@sps-woodland/sorting-header";
204
204
  import { Icon } from "@sps-woodland/core";
205
205
  import { ContentRow } from "@sps-woodland/content-row";
@@ -303,6 +303,6 @@ const L = {
303
303
  };
304
304
  export {
305
305
  G as MANIFEST,
306
- H as SortingHeader,
307
- E as SortingHeaderCell
306
+ k as SortingHeader,
307
+ v as SortingHeaderCell
308
308
  };
@@ -0,0 +1,95 @@
1
+ (function(c,y){typeof exports=="object"&&typeof module<"u"?y(exports,require("react"),require("@sps-woodland/core"),require("@spscommerce/utils")):typeof define=="function"&&define.amd?define(["exports","react","@sps-woodland/core","@spscommerce/utils"],y):(c=typeof globalThis<"u"?globalThis:c||self,y(c.SortingHeader={},c.React,c.core,c.utils))})(this,function(c,y,d,N){"use strict";function I(e){if(e&&e.__esModule)return e;const r=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const t in e)if(t!=="default"){const n=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(r,t,n.get?n:{enumerable:!0,get:()=>e[t]})}}return r.default=e,Object.freeze(r)}const s=I(y),M="";function k(e,r,t){return r in e?Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[r]=t,e}function O(e,r){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);r&&(n=n.filter(function(i){return Object.getOwnPropertyDescriptor(e,i).enumerable})),t.push.apply(t,n)}return t}function D(e){for(var r=1;r<arguments.length;r++){var t=arguments[r]!=null?arguments[r]:{};r%2?O(Object(t),!0).forEach(function(n){k(e,n,t[n])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):O(Object(t)).forEach(function(n){Object.defineProperty(e,n,Object.getOwnPropertyDescriptor(t,n))})}return e}var P=(e,r,t)=>{for(var n of Object.keys(e)){var i;if(e[n]!==((i=r[n])!==null&&i!==void 0?i:t[n]))return!1}return!0},v=e=>r=>{var t=e.defaultClassName,n=D(D({},e.defaultVariants),r);for(var i in n){var l,_=(l=n[i])!==null&&l!==void 0?l:e.defaultVariants[i];if(_!=null){var m=_;typeof m=="boolean"&&(m=m===!0?"true":"false");var u=e.variantClassNames[i][m];u&&(t+=" "+u)}}for(var[f,a]of e.compoundVariants)P(f,n,e.defaultVariants)&&(t+=" "+a);return t},T=v({defaultClassName:"pkg_sps-woodland_sorting-header__version_7_19_0__hash_7ljhcs0",variantClassNames:{up:{true:"pkg_sps-woodland_sorting-header__version_7_19_0__hash_7ljhcs1"},down:{true:"pkg_sps-woodland_sorting-header__version_7_19_0__hash_7ljhcs2"}},defaultVariants:{},compoundVariants:[]});const K="";var A=v({defaultClassName:"pkg_sps-woodland_sorting-header__version_7_19_0__hash_1crs4gl0",variantClassNames:{disabled:{true:"pkg_sps-woodland_sorting-header__version_7_19_0__hash_1crs4gl1"},active:{true:"pkg_sps-woodland_sorting-header__version_7_19_0__hash_1crs4gl2"}},defaultVariants:{disabled:!1,active:!1},compoundVariants:[]});function C({className:e,sortKey:r,sort:t,sortDisabled:n,onSortChange:i,onClick:l,children:_,style:m,widthPx:u,widthRem:f,...a}){const p=s.useMemo(()=>{const h=!!r&&!n&&Array.isArray(t)&&t.find(o=>o.key===r);return h?h.direction:void 0},[t,r,n]),w=u?u/16:f,b=w?{...m,width:`${w}rem`}:m;return s.createElement("div",{className:d.cl(e,A({disabled:n,active:!!p}),p&&T({up:p===d.SortDirection.ASCENDING,down:p===d.SortDirection.DESCENDING})),onClick:h=>{r&&!n&&i&&i([{key:r,direction:p===d.SortDirection.ASCENDING?d.SortDirection.DESCENDING:d.SortDirection.ASCENDING}]),l&&l(h)},style:b,...a},_)}d.Metadata.set(C,{name:"Sorting Header Cell",props:{sortKey:{type:"string"},sort:{type:"SortedColumn[]"},sortDisabled:{type:"boolean"},onSortChange:{type:"SortChangeHandler"},widthPx:{type:"number"},widthRem:{type:"number"}}});const L="";var R=v({defaultClassName:"pkg_sps-woodland_sorting-header__version_7_19_0__hash_sk81640",variantClassNames:{pinned:{true:"pkg_sps-woodland_sorting-header__version_7_19_0__hash_sk81641",false:"pkg_sps-woodland_sorting-header__version_7_19_0__hash_sk81642"}},defaultVariants:{pinned:!1},compoundVariants:[]});function E({sort:e,onSortChange:r,children:t,className:n,pinSortingHeader:i=!1,...l}){const[_,m]=s.useState(!1),u=s.useRef(null),f=s.useRef(null),a=s.useRef({height:"",width:"",unpinAtTop:0,unpinAtBottom:0,cellWidths:[]}),p=s.useCallback(()=>{var o;if(i&&u.current){const g=(o=u.current.parentElement)==null?void 0:o.getBoundingClientRect();if(g){const S=u.current.getBoundingClientRect();a.current.height=`${S.height}px`,a.current.width=`${S.width}px`,a.current.unpinAtBottom=g.bottom+window.scrollY-S.height*2,a.current.unpinAtTop=S.top+window.scrollY-S.height,a.current.cellWidths=[],u.current.childNodes.forEach((H,j)=>{H instanceof HTMLElement&&(a.current.cellWidths[j]=`${H.getBoundingClientRect().width}px`)})}}},[i]),w=s.useCallback(()=>{f.current&&(f.current.style.width=a.current.width,f.current.style.height=a.current.height,f.current.childNodes.forEach((o,g)=>{o instanceof HTMLElement&&(o.style.width=a.current.cellWidths[g]||"")}))},[]);s.useLayoutEffect(()=>{p()}),s.useLayoutEffect(()=>{let o;return i&&(o=N.lockToAnimationFrames(()=>{p();const{unpinAtTop:g,unpinAtBottom:S}=a.current;g&&S&&(window.scrollY>=g&&window.scrollY<=S?m(!0):m(!1))}),window.addEventListener("scroll",o),o()),()=>{o&&window.removeEventListener("scroll",o)}},[i,p]),s.useLayoutEffect(()=>{let o;return _&&(o=()=>{p(),w()},window.addEventListener("resize",o),o()),()=>{o&&window.removeEventListener("resize",o)}},[_,p,w]);const[b]=d.selectChildren(t,[{type:C}]),h=d.modChildren(b,()=>[{sort:e,onSortChange:r}]);return s.createElement(s.Fragment,null,s.createElement("div",{ref:u,className:d.cl(n,R({pinned:!1})),...l},h),_&&s.createElement("div",{ref:f,className:d.cl(n,R({pinned:!0})),...l,id:l.id?`pinned-${l.id}`:void 0,"data-testid":l["data-testid"]?`pinned-${l["data-testid"]}`:void 0},h))}d.Metadata.set(E,{name:"Sorting Header",props:{sort:{type:"SortedColumn[]"},onSortChange:{type:"SortChangeHandler"}}});const V={"Sorting Header":{components:[E,C],examples:{basic:{label:"Sorting Header",examples:{basic:{react:N.code`
2
+ import { SortingHeader, SortingHeaderCell } from "@sps-woodland/sorting-header";
3
+ import { Icon } from "@sps-woodland/core";
4
+ import { ContentRow } from "@sps-woodland/content-row";
5
+ import { KeyValueSet, KeyValueSetItem } from "@sps-woodland/key-value-set";
6
+ import { sprinkles, grid } from "@sps-woodland/tokens";
7
+ function MyComponent() {
8
+ const [sort, setSort] = React.useState([
9
+ { key: "id", direction: SortDirection.DESCENDING },
10
+ ]);
11
+
12
+ const items = React.useMemo(
13
+ () =>
14
+ [
15
+ {
16
+ id: "9712323",
17
+ icon: SpsIcon.STATUS_IN_PROCESS,
18
+ color: "purple-medium",
19
+ type: "850",
20
+ timestamp: "July 21, 2021 @ 4:40 PM",
21
+ },
22
+ {
23
+ id: "8712378",
24
+ icon: SpsIcon.STATUS_OK,
25
+ color: "green-medium",
26
+ type: "810",
27
+ timestamp: "May 24, 2021 @ 4:39 PM",
28
+ },
29
+ {
30
+ id: "8912389",
31
+ icon: SpsIcon.STATUS_REJECTED,
32
+ color: "red-medium",
33
+ type: "850",
34
+ timestamp: "May 23, 2021 @ 4:38 PM",
35
+ },
36
+ ].sort((a, b) => {
37
+ if (!sort.length) {
38
+ return 0;
39
+ }
40
+
41
+ const [{ key, direction }] = sort;
42
+ if (a[key] < b[key]) {
43
+ return direction === SortDirection.ASCENDING ? -1 : 1;
44
+ } else if (a[key] > b[key]) {
45
+ return direction === SortDirection.ASCENDING ? 1 : -1;
46
+ } else {
47
+ return 0;
48
+ }
49
+ }),
50
+ [sort]
51
+ );
52
+
53
+ return (
54
+ <div className={grid.root}>
55
+ <SortingHeader sort={sort} onSortChange={setSort} className={grid[12]}>
56
+ <SortingHeaderCell sortKey="id">ID</SortingHeaderCell>
57
+ <SortingHeaderCell sortKey="type">Type</SortingHeaderCell>
58
+ <SortingHeaderCell sortKey="timestamp" widthPx={150}>
59
+ Timestamp
60
+ </SortingHeaderCell>
61
+ </SortingHeader>
62
+
63
+ {items.map((item) => {
64
+ return (
65
+ <ContentRow key={item.id} className={grid[12]}>
66
+ <ContentRowCol>
67
+ <Icon
68
+ icon={item.icon}
69
+ color={item.color}
70
+ size={SpsIconSize.LARGE}
71
+ className={sprinkles({ mr: "sm" })}
72
+ />
73
+ <a href="#">
74
+ {item.id}
75
+ </a>
76
+ </ContentRowCol>
77
+ <ContentRowCol>
78
+ <KeyValueSet>
79
+ <KeyValueSetItem itemKey="Type">{item.type}</KeyValueSetItem>
80
+ </KeyValueSet>
81
+ </ContentRowCol>
82
+ <ContentRowCol widthPx={250}>
83
+ <KeyValueSet>
84
+ <KeyValueSetItem itemKey="Timestamp">
85
+ {item.timestamp}
86
+ </KeyValueSetItem>
87
+ </KeyValueSet>
88
+ </ContentRowCol>
89
+ </ContentRow>
90
+ );
91
+ })}
92
+ </>
93
+ );
94
+ }
95
+ `}}}}}};c.MANIFEST=V,c.SortingHeader=E,c.SortingHeaderCell=C,Object.defineProperties(c,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
package/lib/style.css CHANGED
@@ -1 +1 @@
1
- ._7ljhcs0:after{content:"";border-left-color:transparent;border-right-color:transparent;border-style:solid;border-width:.375rem .25rem;height:0;position:absolute;right:.5rem}._7ljhcs1:after{border-bottom-color:#1f282c;border-top-color:transparent;top:calc(50% - 9px)}._7ljhcs2:after{border-top-color:#1f282c;border-bottom-color:transparent;top:calc(50% - 3px)}._1crs4gl0{display:table-cell;vertical-align:middle;color:#4b5356;font-size:.75rem;font-weight:600;line-height:1.25rem;padding:.5rem;position:relative}._1crs4gl0:hover{background-color:#f3f4f4}._1crs4gl1{cursor:default}._1crs4gl2{color:#1f282c;background-color:#d2d4d4}.sk81640{display:table;table-layout:fixed;width:100%;padding:0;border-radius:.25rem;vertical-align:bottom;cursor:pointer;background-color:#e9e9ea}.sk81641{border-radius:0;position:fixed;top:3.75rem;z-index:999}.sk81641:after{content:"";background:linear-gradient(180deg,rgba(0,0,0,.1),transparent);display:block;height:.625rem;position:absolute;top:100%;left:-.0625rem;width:100%}
1
+ .pkg_sps-woodland_sorting-header__version_7_19_0__hash_7ljhcs0:after{content:"";border-left-color:transparent;border-right-color:transparent;border-style:solid;border-width:.375rem .25rem;height:0;position:absolute;right:.5rem}.pkg_sps-woodland_sorting-header__version_7_19_0__hash_7ljhcs1:after{border-bottom-color:#1f282c;border-top-color:transparent;top:calc(50% - 9px)}.pkg_sps-woodland_sorting-header__version_7_19_0__hash_7ljhcs2:after{border-top-color:#1f282c;border-bottom-color:transparent;top:calc(50% - 3px)}.pkg_sps-woodland_sorting-header__version_7_19_0__hash_1crs4gl0{display:table-cell;vertical-align:middle;color:#4b5356;font-size:.75rem;font-weight:600;line-height:1.25rem;padding:.5rem;position:relative}.pkg_sps-woodland_sorting-header__version_7_19_0__hash_1crs4gl0:hover{background-color:#f3f4f4}.pkg_sps-woodland_sorting-header__version_7_19_0__hash_1crs4gl1{cursor:default}.pkg_sps-woodland_sorting-header__version_7_19_0__hash_1crs4gl2{color:#1f282c;background-color:#d2d4d4}.pkg_sps-woodland_sorting-header__version_7_19_0__hash_sk81640{display:table;table-layout:fixed;width:100%;padding:0;border-radius:.25rem;vertical-align:bottom;cursor:pointer;background-color:#e9e9ea}.pkg_sps-woodland_sorting-header__version_7_19_0__hash_sk81641{border-radius:0;position:fixed;top:3.75rem;z-index:999}.pkg_sps-woodland_sorting-header__version_7_19_0__hash_sk81641:after{content:"";background:linear-gradient(180deg,rgba(0,0,0,.1),transparent);display:block;height:.625rem;position:absolute;top:100%;left:-.0625rem;width:100%}
package/package.json CHANGED
@@ -1,20 +1,20 @@
1
1
  {
2
2
  "name": "@sps-woodland/sorting-header",
3
3
  "description": "SPS Woodland Design System sorting-header and sorting-header cell components",
4
- "version": "7.17.13",
4
+ "version": "7.19.0",
5
5
  "author": "SPS Commerce",
6
6
  "license": "UNLICENSED",
7
7
  "repository": "https://github.com/SPSCommerce/woodland/tree/main/packages/@sps-woodland/sorting-header",
8
8
  "homepage": "https://github.com/SPSCommerce/woodland/tree/master/packages/@sps-woodland/sorting-header#readme",
9
- "module": "./lib/index.es.js",
10
9
  "type": "module",
11
- "main": "./lib/index.cjs.js",
10
+ "module": "./lib/index.js",
11
+ "main": "./lib/index.umd.cjs",
12
12
  "types": "./lib/index.d.ts",
13
13
  "exports": {
14
14
  ".": {
15
- "import": "./lib/index.es.js",
16
- "require": "./lib/index.cjs.js",
17
- "default": "./lib/index.cjs.js",
15
+ "require": "./lib/index.umd.cjs",
16
+ "import": "./lib/index.js",
17
+ "default": "./lib/index.js",
18
18
  "types": "./lib/index.d.ts"
19
19
  },
20
20
  "./lib/style.css": {
@@ -29,8 +29,8 @@
29
29
  "@spscommerce/utils": "^6.12.1",
30
30
  "react": "^16.14.0",
31
31
  "react-dom": "^16.14.0",
32
- "@sps-woodland/core": "7.17.13",
33
- "@sps-woodland/tokens": "7.17.13"
32
+ "@sps-woodland/tokens": "7.19.0",
33
+ "@sps-woodland/core": "7.19.0"
34
34
  },
35
35
  "devDependencies": {
36
36
  "@spscommerce/utils": "^6.12.1",
@@ -39,8 +39,8 @@
39
39
  "@vanilla-extract/recipes": "^0.2.5",
40
40
  "react": "^16.14.0",
41
41
  "react-dom": "^16.14.0",
42
- "@sps-woodland/core": "7.17.13",
43
- "@sps-woodland/tokens": "7.17.13"
42
+ "@sps-woodland/core": "7.19.0",
43
+ "@sps-woodland/tokens": "7.19.0"
44
44
  },
45
45
  "scripts": {
46
46
  "build": "pnpm run build:js && pnpm run build:types",
package/vite.config.js CHANGED
@@ -1,16 +1,25 @@
1
1
  import path from "path";
2
2
  import { vanillaExtractPlugin } from "@vanilla-extract/vite-plugin";
3
3
  import { defineConfig } from "vite";
4
-
4
+ import { getVanillaExtractPluginProps } from "../../../scripts/vanilla-extract-plugin-props.js";
5
5
  import pkg from "./package.json";
6
6
 
7
+ const packageVersion = process.env.PREDICTED_VERSION || pkg.version;
8
+
7
9
  export default defineConfig({
8
- plugins: [vanillaExtractPlugin()],
10
+ plugins: [
11
+ vanillaExtractPlugin(
12
+ getVanillaExtractPluginProps({
13
+ packageName: pkg.name,
14
+ packageVersion,
15
+ })
16
+ ),
17
+ ],
9
18
  build: {
10
19
  lib: {
11
20
  entry: path.resolve(__dirname, "src/index.ts"),
12
- formats: ["es", "cjs"],
13
- fileName: (format) => `index.${format}.js`,
21
+ name: "SortingHeader",
22
+ fileName: "index",
14
23
  },
15
24
  outDir: path.resolve(__dirname, "./lib"),
16
25
  emptyOutDir: false,
package/lib/index.cjs.js DELETED
@@ -1,95 +0,0 @@
1
- "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const _=require("react"),c=require("@sps-woodland/core"),R=require("@spscommerce/utils");function H(e){if(e&&e.__esModule)return e;const n=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const t in e)if(t!=="default"){const r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(n,t,r.get?r:{enumerable:!0,get:()=>e[t]})}}return n.default=e,Object.freeze(n)}const a=H(_);function P(e,n,t){return n in e?Object.defineProperty(e,n,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[n]=t,e}function N(e,n){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);n&&(r=r.filter(function(i){return Object.getOwnPropertyDescriptor(e,i).enumerable})),t.push.apply(t,r)}return t}function O(e){for(var n=1;n<arguments.length;n++){var t=arguments[n]!=null?arguments[n]:{};n%2?N(Object(t),!0).forEach(function(r){P(e,r,t[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):N(Object(t)).forEach(function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(t,r))})}return e}var A=(e,n,t)=>{for(var r of Object.keys(e)){var i;if(e[r]!==((i=n[r])!==null&&i!==void 0?i:t[r]))return!1}return!0},v=e=>n=>{var t=e.defaultClassName,r=O(O({},e.defaultVariants),n);for(var i in r){var l,f=(l=r[i])!==null&&l!==void 0?l:e.defaultVariants[i];if(f!=null){var m=f;typeof m=="boolean"&&(m=m===!0?"true":"false");var d=e.variantClassNames[i][m];d&&(t+=" "+d)}}for(var[p,s]of e.compoundVariants)A(p,r,e.defaultVariants)&&(t+=" "+s);return t},T=v({defaultClassName:"_7ljhcs0",variantClassNames:{up:{true:"_7ljhcs1"},down:{true:"_7ljhcs2"}},defaultVariants:{},compoundVariants:[]});var V=v({defaultClassName:"_1crs4gl0",variantClassNames:{disabled:{true:"_1crs4gl1"},active:{true:"_1crs4gl2"}},defaultVariants:{disabled:!1,active:!1},compoundVariants:[]});function w({className:e,sortKey:n,sort:t,sortDisabled:r,onSortChange:i,onClick:l,children:f,style:m,widthPx:d,widthRem:p,...s}){const u=a.useMemo(()=>{const y=!!n&&!r&&Array.isArray(t)&&t.find(o=>o.key===n);return y?y.direction:void 0},[t,n,r]),g=d?d/16:p,h=g?{...m,width:`${g}rem`}:m;return a.createElement("div",{className:c.cl(e,V({disabled:r,active:!!u}),u&&T({up:u===c.SortDirection.ASCENDING,down:u===c.SortDirection.DESCENDING})),onClick:y=>{n&&!r&&i&&i([{key:n,direction:u===c.SortDirection.ASCENDING?c.SortDirection.DESCENDING:c.SortDirection.ASCENDING}]),l&&l(y)},style:h,...s},f)}c.Metadata.set(w,{name:"Sorting Header Cell",props:{sortKey:{type:"string"},sort:{type:"SortedColumn[]"},sortDisabled:{type:"boolean"},onSortChange:{type:"SortChangeHandler"},widthPx:{type:"number"},widthRem:{type:"number"}}});var D=v({defaultClassName:"sk81640",variantClassNames:{pinned:{true:"sk81641",false:"sk81642"}},defaultVariants:{pinned:!1},compoundVariants:[]});function E({sort:e,onSortChange:n,children:t,className:r,pinSortingHeader:i=!1,...l}){const[f,m]=a.useState(!1),d=a.useRef(null),p=a.useRef(null),s=a.useRef({height:"",width:"",unpinAtTop:0,unpinAtBottom:0,cellWidths:[]}),u=a.useCallback(()=>{var o;if(i&&d.current){const C=(o=d.current.parentElement)==null?void 0:o.getBoundingClientRect();if(C){const S=d.current.getBoundingClientRect();s.current.height=`${S.height}px`,s.current.width=`${S.width}px`,s.current.unpinAtBottom=C.bottom+window.scrollY-S.height*2,s.current.unpinAtTop=S.top+window.scrollY-S.height,s.current.cellWidths=[],d.current.childNodes.forEach((b,I)=>{b instanceof HTMLElement&&(s.current.cellWidths[I]=`${b.getBoundingClientRect().width}px`)})}}},[i]),g=a.useCallback(()=>{p.current&&(p.current.style.width=s.current.width,p.current.style.height=s.current.height,p.current.childNodes.forEach((o,C)=>{o instanceof HTMLElement&&(o.style.width=s.current.cellWidths[C]||"")}))},[]);a.useLayoutEffect(()=>{u()}),a.useLayoutEffect(()=>{let o;return i&&(o=R.lockToAnimationFrames(()=>{u();const{unpinAtTop:C,unpinAtBottom:S}=s.current;C&&S&&(window.scrollY>=C&&window.scrollY<=S?m(!0):m(!1))}),window.addEventListener("scroll",o),o()),()=>{o&&window.removeEventListener("scroll",o)}},[i,u]),a.useLayoutEffect(()=>{let o;return f&&(o=()=>{u(),g()},window.addEventListener("resize",o),o()),()=>{o&&window.removeEventListener("resize",o)}},[f,u,g]);const[h]=c.selectChildren(t,[{type:w}]),y=c.modChildren(h,()=>[{sort:e,onSortChange:n}]);return a.createElement(a.Fragment,null,a.createElement("div",{ref:d,className:c.cl(r,D({pinned:!1})),...l},y),f&&a.createElement("div",{ref:p,className:c.cl(r,D({pinned:!0})),...l,id:l.id?`pinned-${l.id}`:void 0,"data-testid":l["data-testid"]?`pinned-${l["data-testid"]}`:void 0},y))}c.Metadata.set(E,{name:"Sorting Header",props:{sort:{type:"SortedColumn[]"},onSortChange:{type:"SortChangeHandler"}}});const M={components:[E,w],examples:{basic:{label:"Sorting Header",examples:{basic:{react:R.code`
2
- import { SortingHeader, SortingHeaderCell } from "@sps-woodland/sorting-header";
3
- import { Icon } from "@sps-woodland/core";
4
- import { ContentRow } from "@sps-woodland/content-row";
5
- import { KeyValueSet, KeyValueSetItem } from "@sps-woodland/key-value-set";
6
- import { sprinkles, grid } from "@sps-woodland/tokens";
7
- function MyComponent() {
8
- const [sort, setSort] = React.useState([
9
- { key: "id", direction: SortDirection.DESCENDING },
10
- ]);
11
-
12
- const items = React.useMemo(
13
- () =>
14
- [
15
- {
16
- id: "9712323",
17
- icon: SpsIcon.STATUS_IN_PROCESS,
18
- color: "purple-medium",
19
- type: "850",
20
- timestamp: "July 21, 2021 @ 4:40 PM",
21
- },
22
- {
23
- id: "8712378",
24
- icon: SpsIcon.STATUS_OK,
25
- color: "green-medium",
26
- type: "810",
27
- timestamp: "May 24, 2021 @ 4:39 PM",
28
- },
29
- {
30
- id: "8912389",
31
- icon: SpsIcon.STATUS_REJECTED,
32
- color: "red-medium",
33
- type: "850",
34
- timestamp: "May 23, 2021 @ 4:38 PM",
35
- },
36
- ].sort((a, b) => {
37
- if (!sort.length) {
38
- return 0;
39
- }
40
-
41
- const [{ key, direction }] = sort;
42
- if (a[key] < b[key]) {
43
- return direction === SortDirection.ASCENDING ? -1 : 1;
44
- } else if (a[key] > b[key]) {
45
- return direction === SortDirection.ASCENDING ? 1 : -1;
46
- } else {
47
- return 0;
48
- }
49
- }),
50
- [sort]
51
- );
52
-
53
- return (
54
- <div className={grid.root}>
55
- <SortingHeader sort={sort} onSortChange={setSort} className={grid[12]}>
56
- <SortingHeaderCell sortKey="id">ID</SortingHeaderCell>
57
- <SortingHeaderCell sortKey="type">Type</SortingHeaderCell>
58
- <SortingHeaderCell sortKey="timestamp" widthPx={150}>
59
- Timestamp
60
- </SortingHeaderCell>
61
- </SortingHeader>
62
-
63
- {items.map((item) => {
64
- return (
65
- <ContentRow key={item.id} className={grid[12]}>
66
- <ContentRowCol>
67
- <Icon
68
- icon={item.icon}
69
- color={item.color}
70
- size={SpsIconSize.LARGE}
71
- className={sprinkles({ mr: "sm" })}
72
- />
73
- <a href="#">
74
- {item.id}
75
- </a>
76
- </ContentRowCol>
77
- <ContentRowCol>
78
- <KeyValueSet>
79
- <KeyValueSetItem itemKey="Type">{item.type}</KeyValueSetItem>
80
- </KeyValueSet>
81
- </ContentRowCol>
82
- <ContentRowCol widthPx={250}>
83
- <KeyValueSet>
84
- <KeyValueSetItem itemKey="Timestamp">
85
- {item.timestamp}
86
- </KeyValueSetItem>
87
- </KeyValueSet>
88
- </ContentRowCol>
89
- </ContentRow>
90
- );
91
- })}
92
- </>
93
- );
94
- }
95
- `}}}}},j={"Sorting Header":M};exports.MANIFEST=j;exports.SortingHeader=E;exports.SortingHeaderCell=w;