@sps-woodland/sorting-header 8.7.7 → 8.8.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/lib/index.cjs.js CHANGED
@@ -1,4 +1,4 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const P=require("react"),c=require("@sps-woodland/core"),R=require("@spscommerce/utils");function A(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=A(P);function H(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 D(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){H(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 T=(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=D(D({},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)T(p,r,e.defaultVariants)&&(t+=" "+s);return t},V=v({defaultClassName:"_7ljhcs0",variantClassNames:{up:{true:"_7ljhcs1"},down:{true:"_7ljhcs2"}},defaultVariants:{},compoundVariants:[]}),j=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,j({disabled:r,active:!!u}),u&&V({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 O=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,O({pinned:!1})),...l},y),f&&a.createElement("div",{ref:p,className:c.cl(r,O({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`
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const L=require("react"),a=require("@sps-woodland/core"),G=require("@spscommerce/utils");function x(e){const n=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const r in e)if(r!=="default"){const t=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(n,r,t.get?t:{enumerable:!0,get:()=>e[r]})}}return n.default=e,Object.freeze(n)}const i=x(L);function W(e,n,r){return n in e?Object.defineProperty(e,n,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[n]=r,e}function V(e,n){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var t=Object.getOwnPropertySymbols(e);n&&(t=t.filter(function(c){return Object.getOwnPropertyDescriptor(e,c).enumerable})),r.push.apply(r,t)}return r}function j(e){for(var n=1;n<arguments.length;n++){var r=arguments[n]!=null?arguments[n]:{};n%2?V(Object(r),!0).forEach(function(t){W(e,t,r[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):V(Object(r)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))})}return e}var _=(e,n,r)=>{for(var t of Object.keys(e)){var c;if(e[t]!==((c=n[t])!==null&&c!==void 0?c:r[t]))return!1}return!0},A=e=>n=>{var r=e.defaultClassName,t=j(j({},e.defaultVariants),n);for(var c in t){var p,s=(p=t[c])!==null&&p!==void 0?p:e.defaultVariants[c];if(s!=null){var m=s;typeof m=="boolean"&&(m=m===!0?"true":"false");var y=e.variantClassNames[c][m];y&&(r+=" "+y)}}for(var[l,f]of e.compoundVariants)_(l,t,e.defaultVariants)&&(r+=" "+f);return r},M=A({defaultClassName:"_7ljhcs0",variantClassNames:{up:{true:"_7ljhcs1"},down:{true:"_7ljhcs2"}},defaultVariants:{},compoundVariants:[]}),K=A({defaultClassName:"_1crs4gl0",variantClassNames:{disabled:{true:"_1crs4gl1"},active:{true:"_1crs4gl2"},__autoLayout:{true:"_1crs4gl3",false:"_1crs4gl4"}},defaultVariants:{disabled:!1,active:!1,__autoLayout:!1},compoundVariants:[]});function k({className:e,sortKey:n,sort:r,sortDisabled:t,onSortChange:c,onClick:p,children:s,style:m,widthPx:y,widthRem:l,__autoLayout:f=!1,...d}){const u=i.useMemo(()=>{const g=!!n&&!t&&Array.isArray(r)&&r.find(w=>w.key===n);return g?g.direction:void 0},[r,n,t]),E=y?y/16:l,C=E?{...m,width:`${E}rem`}:m,v=g=>{n&&!t&&c&&c([{key:n,direction:u===a.SortDirection.ASCENDING?a.SortDirection.DESCENDING:a.SortDirection.ASCENDING}]),p&&p(g)};return f?i.createElement("td",{className:a.cl(e,K({disabled:t,active:!!u,__autoLayout:f}),u&&M({up:u===a.SortDirection.ASCENDING,down:u===a.SortDirection.DESCENDING})),onClick:v,style:C,...d},s):i.createElement("div",{className:a.cl(e,K({disabled:t,active:!!u,__autoLayout:f}),u&&M({up:u===a.SortDirection.ASCENDING,down:u===a.SortDirection.DESCENDING})),onClick:v,style:C,...d},s)}a.Metadata.set(k,{name:"Sorting Header Cell",props:{sortKey:{type:"string"},sort:{type:"SortedColumn[]"},sortDisabled:{type:"boolean"},onSortChange:{type:"SortChangeHandler"},widthPx:{type:"number"},widthRem:{type:"number"}}});var R=A({defaultClassName:"sk81640",variantClassNames:{pinned:{true:"sk81641",false:"sk81642"},scrollParentIsWindow:{true:"sk81643",false:"sk81644"},__autoLayout:{true:"sk81645",false:"sk81646"}},defaultVariants:{pinned:!1,scrollParentIsWindow:!1,__autoLayout:!1},compoundVariants:[[{pinned:!0,scrollParentIsWindow:!0},"sk81647"]]}),z="sk81648";function T({sort:e,onSortChange:n,children:r,className:t,pinSortingHeader:c=!1,__autoLayout:p=!1,...s}){const[m,y]=i.useState(!1),l=i.useRef(null),f=i.useRef(null),d=i.useRef({height:"",width:"",unpinAtTop:0,unpinAtBottom:0,cellWidths:[]}),u=i.useCallback(()=>l.current&&a.getScrollParent(l.current)||window,[]),E=i.useCallback(o=>{const S=o||u();return S.scrollY||S.scrollTop||0},[]),C=i.useCallback(o=>{var S,b,N;if(c&&l.current){const P=o||u(),I=E(P),O=p?(b=(S=l.current.parentElement)==null?void 0:S.parentElement)==null?void 0:b.getBoundingClientRect():(N=l.current.parentElement)==null?void 0:N.getBoundingClientRect();if(O){const h=l.current.getBoundingClientRect();d.current.height=`${h.height}px`,d.current.width=`${h.width}px`,P===window?(d.current.unpinAtBottom=O.bottom+I-h.height*2,d.current.unpinAtTop=h.top+I-h.height):(d.current.unpinAtBottom=O.bottom+I-h.height*2,d.current.unpinAtTop=O.top+I),d.current.cellWidths=[],l.current.childNodes.forEach((H,B)=>{H instanceof HTMLElement&&(d.current.cellWidths[B]=`${H.getBoundingClientRect().width}px`)})}}},[c]),v=i.useCallback(()=>{f.current&&(f.current.style.width=d.current.width,f.current.style.height=d.current.height,f.current.childNodes.forEach((o,S)=>{o instanceof HTMLElement&&(o.style.width=d.current.cellWidths[S]||"")}))},[]);i.useLayoutEffect(()=>{C()}),i.useLayoutEffect(()=>{let o;const S=u();return c?(o=G.lockToAnimationFrames(()=>{C(S);const{unpinAtTop:b,unpinAtBottom:N}=d.current,P=E(S);b&&N&&(P>=b&&P<=N?(y(!0),l.current&&(l.current.style.visibility="hidden")):(y(!1),l.current&&(l.current.style.visibility="visible")))}),S.addEventListener("scroll",o),o()):l.current&&(l.current.style.visibility="visible"),()=>{o&&S.removeEventListener("scroll",o)}},[c,C]),i.useLayoutEffect(()=>{let o;return m&&(o=()=>{C(),v()},window.addEventListener("resize",o),o()),()=>{o&&window.removeEventListener("resize",o)}},[m,C,v]);const[g]=a.selectChildren(r,[{type:k}]),w=a.modChildren(g,()=>[{sort:e,onSortChange:n}]),D=u()===window;if(p){const o=i.createElement("tr",null,i.createElement("td",{className:a.cl(z),colSpan:100}));return i.createElement(i.Fragment,null,i.createElement("tr",{ref:l,className:a.cl(R({pinned:!1,scrollParentIsWindow:D,__autoLayout:p}),t),...s},w),o,m&&i.createElement("tr",{ref:f,className:a.cl(t,R({pinned:!0,scrollParentIsWindow:D,__autoLayout:p})),...s,id:s.id?`pinned-${s.id}`:void 0,"data-testid":s["data-testid"]?`pinned-${s["data-testid"]}`:void 0},w))}return i.createElement(i.Fragment,null,i.createElement("div",{ref:l,className:a.cl(t,R({pinned:!1,scrollParentIsWindow:D,__autoLayout:p})),...s},w),m&&i.createElement("div",{ref:f,className:a.cl(t,R({pinned:!0,scrollParentIsWindow:D,__autoLayout:p})),...s,id:s.id?`pinned-${s.id}`:void 0,"data-testid":s["data-testid"]?`pinned-${s["data-testid"]}`:void 0},w))}a.Metadata.set(T,{name:"Sorting Header",props:{sort:{type:"SortedColumn[]"},onSortChange:{type:"SortChangeHandler"}}});const F={components:[T,k],examples:{basic:{label:"Sorting Header",examples:{basic:{react:G.code`
2
2
  import { SortingHeader, SortingHeaderCell } from "@sps-woodland/sorting-header";
3
3
  import { Icon } from "@sps-woodland/core";
4
4
  import { ContentRow } from "@sps-woodland/content-row";
@@ -92,4 +92,4 @@
92
92
  </>
93
93
  );
94
94
  }
95
- `}}}}},k={"Sorting Header":M};exports.MANIFEST=k;exports.SortingHeader=E;exports.SortingHeaderCell=w;
95
+ `}}}}},Y={"Sorting Header":F};exports.MANIFEST=Y;exports.SortingHeader=T;exports.SortingHeaderCell=k;
package/lib/index.es.js CHANGED
@@ -1,107 +1,120 @@
1
- import * as a from "react";
2
- import { Metadata as D, cl as g, SortDirection as w, selectChildren as P, modChildren as V } from "@sps-woodland/core";
3
- import { lockToAnimationFrames as H, code as T } from "@spscommerce/utils";
4
- function K(e, n, r) {
5
- return n in e ? Object.defineProperty(e, n, {
1
+ import * as n from "react";
2
+ import { Metadata as G, cl as g, SortDirection as y, getScrollParent as L, selectChildren as W, modChildren as z } from "@sps-woodland/core";
3
+ import { lockToAnimationFrames as F, code as Y } from "@spscommerce/utils";
4
+ function _(e, i, r) {
5
+ return i in e ? Object.defineProperty(e, i, {
6
6
  value: r,
7
7
  enumerable: !0,
8
8
  configurable: !0,
9
9
  writable: !0
10
- }) : e[n] = r, e;
10
+ }) : e[i] = r, e;
11
11
  }
12
- function b(e, n) {
12
+ function V(e, i) {
13
13
  var r = Object.keys(e);
14
14
  if (Object.getOwnPropertySymbols) {
15
15
  var t = Object.getOwnPropertySymbols(e);
16
- n && (t = t.filter(function(i) {
17
- return Object.getOwnPropertyDescriptor(e, i).enumerable;
16
+ i && (t = t.filter(function(s) {
17
+ return Object.getOwnPropertyDescriptor(e, s).enumerable;
18
18
  })), r.push.apply(r, t);
19
19
  }
20
20
  return r;
21
21
  }
22
- function R(e) {
23
- for (var n = 1; n < arguments.length; n++) {
24
- var r = arguments[n] != null ? arguments[n] : {};
25
- n % 2 ? b(Object(r), !0).forEach(function(t) {
26
- K(e, t, r[t]);
27
- }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(r)) : b(Object(r)).forEach(function(t) {
22
+ function K(e) {
23
+ for (var i = 1; i < arguments.length; i++) {
24
+ var r = arguments[i] != null ? arguments[i] : {};
25
+ i % 2 ? V(Object(r), !0).forEach(function(t) {
26
+ _(e, t, r[t]);
27
+ }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(r)) : V(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 $ = (e, i, r) => {
34
34
  for (var t of Object.keys(e)) {
35
- var i;
36
- if (e[t] !== ((i = n[t]) !== null && i !== void 0 ? i : r[t]))
35
+ var s;
36
+ if (e[t] !== ((s = i[t]) !== null && s !== void 0 ? s : r[t]))
37
37
  return !1;
38
38
  }
39
39
  return !0;
40
- }, E = (e) => (n) => {
41
- var r = e.defaultClassName, t = R(R({}, e.defaultVariants), n);
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;
46
- typeof u == "boolean" && (u = u === !0 ? "true" : "false");
47
- var d = (
40
+ }, O = (e) => (i) => {
41
+ var r = e.defaultClassName, t = K(K({}, e.defaultVariants), i);
42
+ for (var s in t) {
43
+ var u, a = (u = t[s]) !== null && u !== void 0 ? u : e.defaultVariants[s];
44
+ if (a != null) {
45
+ var m = a;
46
+ typeof m == "boolean" && (m = m === !0 ? "true" : "false");
47
+ var S = (
48
48
  // @ts-expect-error
49
- e.variantClassNames[i][u]
49
+ e.variantClassNames[s][m]
50
50
  );
51
- d && (r += " " + d);
51
+ S && (r += " " + S);
52
52
  }
53
53
  }
54
- for (var [m, s] of e.compoundVariants)
55
- k(m, t, e.defaultVariants) && (r += " " + s);
54
+ for (var [l, p] of e.compoundVariants)
55
+ $(l, t, e.defaultVariants) && (r += " " + p);
56
56
  return r;
57
- }, j = E({ defaultClassName: "_7ljhcs0", variantClassNames: { up: { true: "_7ljhcs1" }, down: { true: "_7ljhcs2" } }, defaultVariants: {}, compoundVariants: [] }), L = E({ defaultClassName: "_1crs4gl0", variantClassNames: { disabled: { true: "_1crs4gl1" }, active: { true: "_1crs4gl2" } }, defaultVariants: { disabled: !1, active: !1 }, compoundVariants: [] });
58
- function v({
57
+ }, j = O({ defaultClassName: "_7ljhcs0", variantClassNames: { up: { true: "_7ljhcs1" }, down: { true: "_7ljhcs2" } }, defaultVariants: {}, compoundVariants: [] }), M = O({ defaultClassName: "_1crs4gl0", variantClassNames: { disabled: { true: "_1crs4gl1" }, active: { true: "_1crs4gl2" }, __autoLayout: { true: "_1crs4gl3", false: "_1crs4gl4" } }, defaultVariants: { disabled: !1, active: !1, __autoLayout: !1 }, compoundVariants: [] });
58
+ function H({
59
59
  className: e,
60
- sortKey: n,
60
+ sortKey: i,
61
61
  sort: r,
62
62
  sortDisabled: t,
63
- onSortChange: i,
64
- onClick: l,
65
- children: p,
66
- style: u,
67
- widthPx: d,
68
- widthRem: m,
69
- ...s
63
+ onSortChange: s,
64
+ onClick: u,
65
+ children: a,
66
+ style: m,
67
+ widthPx: S,
68
+ widthRem: l,
69
+ __autoLayout: p = !1,
70
+ ...c
70
71
  }) {
71
- const c = a.useMemo(() => {
72
- const S = !!n && !t && Array.isArray(r) && r.find((o) => o.key === n);
73
- return S ? S.direction : void 0;
74
- }, [
75
- r,
76
- n,
77
- t
78
- ]), C = d ? d / 16 : m, h = C ? { ...u, width: `${C}rem` } : u;
79
- return /* @__PURE__ */ a.createElement(
72
+ const d = n.useMemo(() => {
73
+ const w = !!i && !t && Array.isArray(r) && r.find((h) => h.key === i);
74
+ return w ? w.direction : void 0;
75
+ }, [r, i, t]), v = S ? S / 16 : l, C = v ? { ...m, width: `${v}rem` } : m, b = (w) => {
76
+ i && !t && s && s([
77
+ {
78
+ key: i,
79
+ direction: d === y.ASCENDING ? y.DESCENDING : y.ASCENDING
80
+ }
81
+ ]), u && u(w);
82
+ };
83
+ return p ? /* @__PURE__ */ n.createElement(
84
+ "td",
85
+ {
86
+ className: g(
87
+ e,
88
+ M({ disabled: t, active: !!d, __autoLayout: p }),
89
+ d && j({
90
+ up: d === y.ASCENDING,
91
+ down: d === y.DESCENDING
92
+ })
93
+ ),
94
+ onClick: b,
95
+ style: C,
96
+ ...c
97
+ },
98
+ a
99
+ ) : /* @__PURE__ */ n.createElement(
80
100
  "div",
81
101
  {
82
102
  className: g(
83
103
  e,
84
- L({ disabled: t, active: !!c }),
85
- c && j({
86
- up: c === w.ASCENDING,
87
- down: c === w.DESCENDING
104
+ M({ disabled: t, active: !!d, __autoLayout: p }),
105
+ d && j({
106
+ up: d === y.ASCENDING,
107
+ down: d === y.DESCENDING
88
108
  })
89
109
  ),
90
- onClick: (S) => {
91
- n && !t && i && i([
92
- {
93
- key: n,
94
- direction: c === w.ASCENDING ? w.DESCENDING : w.ASCENDING
95
- }
96
- ]), l && l(S);
97
- },
98
- style: h,
99
- ...s
110
+ onClick: b,
111
+ style: C,
112
+ ...c
100
113
  },
101
- p
114
+ a
102
115
  );
103
116
  }
104
- D.set(v, {
117
+ G.set(H, {
105
118
  name: "Sorting Header Cell",
106
119
  props: {
107
120
  sortKey: { type: "string" },
@@ -112,96 +125,134 @@ D.set(v, {
112
125
  widthRem: { type: "number" }
113
126
  }
114
127
  });
115
- var I = E({ defaultClassName: "sk81640", variantClassNames: { pinned: { true: "sk81641", false: "sk81642" } }, defaultVariants: { pinned: !1 }, compoundVariants: [] });
116
- function O({
128
+ var D = O({ defaultClassName: "sk81640", variantClassNames: { pinned: { true: "sk81641", false: "sk81642" }, scrollParentIsWindow: { true: "sk81643", false: "sk81644" }, __autoLayout: { true: "sk81645", false: "sk81646" } }, defaultVariants: { pinned: !1, scrollParentIsWindow: !1, __autoLayout: !1 }, compoundVariants: [[{ pinned: !0, scrollParentIsWindow: !0 }, "sk81647"]] }), U = "sk81648";
129
+ function B({
117
130
  sort: e,
118
- onSortChange: n,
131
+ onSortChange: i,
119
132
  children: r,
120
133
  className: t,
121
- pinSortingHeader: i = !1,
122
- ...l
134
+ pinSortingHeader: s = !1,
135
+ __autoLayout: u = !1,
136
+ ...a
123
137
  }) {
124
- const [p, u] = a.useState(!1), d = a.useRef(null), m = a.useRef(null), s = a.useRef({
138
+ const [m, S] = n.useState(!1), l = n.useRef(null), p = n.useRef(null), c = n.useRef({
125
139
  height: "",
126
140
  width: "",
127
141
  unpinAtTop: 0,
128
142
  unpinAtBottom: 0,
129
143
  cellWidths: []
130
- }), c = a.useCallback(() => {
131
- var o;
132
- if (i && d.current) {
133
- const y = (o = d.current.parentElement) == null ? void 0 : o.getBoundingClientRect();
134
- if (y) {
135
- const f = d.current.getBoundingClientRect();
136
- 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, A) => {
137
- N instanceof HTMLElement && (s.current.cellWidths[A] = `${N.getBoundingClientRect().width}px`);
138
- });
144
+ }), d = n.useCallback(() => l.current && L(l.current) || window, []), v = n.useCallback((o) => {
145
+ const f = o || d();
146
+ return f.scrollY || f.scrollTop || 0;
147
+ }, []), C = n.useCallback(
148
+ (o) => {
149
+ var f, N, I;
150
+ if (s && l.current) {
151
+ const P = o || d(), k = v(P), A = u ? (N = (f = l.current.parentElement) == null ? void 0 : f.parentElement) == null ? void 0 : N.getBoundingClientRect() : (I = l.current.parentElement) == null ? void 0 : I.getBoundingClientRect();
152
+ if (A) {
153
+ const E = l.current.getBoundingClientRect();
154
+ c.current.height = `${E.height}px`, c.current.width = `${E.width}px`, P === window ? (c.current.unpinAtBottom = A.bottom + k - E.height * 2, c.current.unpinAtTop = E.top + k - E.height) : (c.current.unpinAtBottom = A.bottom + k - E.height * 2, c.current.unpinAtTop = A.top + k), c.current.cellWidths = [], l.current.childNodes.forEach((T, x) => {
155
+ T instanceof HTMLElement && (c.current.cellWidths[x] = `${T.getBoundingClientRect().width}px`);
156
+ });
157
+ }
139
158
  }
140
- }
141
- }, [i]), C = a.useCallback(() => {
142
- m.current && (m.current.style.width = s.current.width, m.current.style.height = s.current.height, m.current.childNodes.forEach((o, y) => {
143
- o instanceof HTMLElement && (o.style.width = s.current.cellWidths[y] || "");
159
+ },
160
+ [s]
161
+ ), b = n.useCallback(() => {
162
+ p.current && (p.current.style.width = c.current.width, p.current.style.height = c.current.height, p.current.childNodes.forEach((o, f) => {
163
+ o instanceof HTMLElement && (o.style.width = c.current.cellWidths[f] || "");
144
164
  }));
145
165
  }, []);
146
- a.useLayoutEffect(() => {
147
- c();
148
- }), a.useLayoutEffect(() => {
166
+ n.useLayoutEffect(() => {
167
+ C();
168
+ }), n.useLayoutEffect(() => {
149
169
  let o;
150
- return i && (o = H(() => {
151
- c();
152
- const { unpinAtTop: y, unpinAtBottom: f } = s.current;
153
- y && f && (window.scrollY >= y && window.scrollY <= f ? u(!0) : u(!1));
154
- }), window.addEventListener("scroll", o), o()), () => {
155
- o && window.removeEventListener("scroll", o);
170
+ const f = d();
171
+ return s ? (o = F(() => {
172
+ C(f);
173
+ const { unpinAtTop: N, unpinAtBottom: I } = c.current, P = v(f);
174
+ N && I && (P >= N && P <= I ? (S(!0), l.current && (l.current.style.visibility = "hidden")) : (S(!1), l.current && (l.current.style.visibility = "visible")));
175
+ }), f.addEventListener("scroll", o), o()) : l.current && (l.current.style.visibility = "visible"), () => {
176
+ o && f.removeEventListener("scroll", o);
156
177
  };
157
- }, [i, c]), a.useLayoutEffect(() => {
178
+ }, [s, C]), n.useLayoutEffect(() => {
158
179
  let o;
159
- return p && (o = () => {
160
- c(), C();
180
+ return m && (o = () => {
181
+ C(), b();
161
182
  }, window.addEventListener("resize", o), o()), () => {
162
183
  o && window.removeEventListener("resize", o);
163
184
  };
164
- }, [
165
- p,
166
- c,
167
- C
168
- ]);
169
- const [h] = P(r, [{ type: v }]), S = V(h, () => [{ sort: e, onSortChange: n }]);
170
- return /* @__PURE__ */ a.createElement(a.Fragment, null, /* @__PURE__ */ a.createElement(
185
+ }, [m, C, b]);
186
+ const [w] = W(r, [{ type: H }]), h = z(w, () => [{ sort: e, onSortChange: i }]), R = d() === window;
187
+ if (u) {
188
+ const o = /* @__PURE__ */ n.createElement("tr", null, /* @__PURE__ */ n.createElement("td", { className: g(U), colSpan: 100 }));
189
+ return /* @__PURE__ */ n.createElement(n.Fragment, null, /* @__PURE__ */ n.createElement(
190
+ "tr",
191
+ {
192
+ ref: l,
193
+ className: g(
194
+ D({ pinned: !1, scrollParentIsWindow: R, __autoLayout: u }),
195
+ t
196
+ ),
197
+ ...a
198
+ },
199
+ h
200
+ ), o, m && /* @__PURE__ */ n.createElement(
201
+ "tr",
202
+ {
203
+ ref: p,
204
+ className: g(
205
+ t,
206
+ D({ pinned: !0, scrollParentIsWindow: R, __autoLayout: u })
207
+ ),
208
+ ...a,
209
+ id: a.id ? `pinned-${a.id}` : void 0,
210
+ "data-testid": a["data-testid"] ? `pinned-${a["data-testid"]}` : void 0
211
+ },
212
+ h
213
+ ));
214
+ }
215
+ return /* @__PURE__ */ n.createElement(n.Fragment, null, /* @__PURE__ */ n.createElement(
171
216
  "div",
172
217
  {
173
- ref: d,
174
- className: g(t, I({ pinned: !1 })),
175
- ...l
218
+ ref: l,
219
+ className: g(
220
+ t,
221
+ D({ pinned: !1, scrollParentIsWindow: R, __autoLayout: u })
222
+ ),
223
+ ...a
176
224
  },
177
- S
178
- ), p && /* @__PURE__ */ a.createElement(
225
+ h
226
+ ), m && /* @__PURE__ */ n.createElement(
179
227
  "div",
180
228
  {
181
- ref: m,
182
- className: g(t, I({ pinned: !0 })),
183
- ...l,
184
- id: l.id ? `pinned-${l.id}` : void 0,
185
- "data-testid": l["data-testid"] ? `pinned-${l["data-testid"]}` : void 0
229
+ ref: p,
230
+ className: g(
231
+ t,
232
+ D({ pinned: !0, scrollParentIsWindow: R, __autoLayout: u })
233
+ ),
234
+ ...a,
235
+ id: a.id ? `pinned-${a.id}` : void 0,
236
+ "data-testid": a["data-testid"] ? `pinned-${a["data-testid"]}` : void 0
186
237
  },
187
- S
238
+ h
188
239
  ));
189
240
  }
190
- D.set(O, {
241
+ G.set(B, {
191
242
  name: "Sorting Header",
192
243
  props: {
193
244
  sort: { type: "SortedColumn[]" },
194
245
  onSortChange: { type: "SortChangeHandler" }
195
246
  }
196
247
  });
197
- const M = {
198
- components: [O, v],
248
+ const J = {
249
+ components: [B, H],
199
250
  examples: {
200
251
  basic: {
201
252
  label: "Sorting Header",
202
253
  examples: {
203
254
  basic: {
204
- react: T`
255
+ react: Y`
205
256
  import { SortingHeader, SortingHeaderCell } from "@sps-woodland/sorting-header";
206
257
  import { Icon } from "@sps-woodland/core";
207
258
  import { ContentRow } from "@sps-woodland/content-row";
@@ -300,11 +351,11 @@ const M = {
300
351
  }
301
352
  }
302
353
  }
303
- }, B = {
304
- "Sorting Header": M
354
+ }, X = {
355
+ "Sorting Header": J
305
356
  };
306
357
  export {
307
- B as MANIFEST,
308
- O as SortingHeader,
309
- v as SortingHeaderCell
358
+ X as MANIFEST,
359
+ B as SortingHeader,
360
+ H as SortingHeaderCell
310
361
  };
@@ -3,7 +3,7 @@ export declare const sortingHeader: import("@vanilla-extract/recipes/dist/declar
3
3
  true: {
4
4
  borderRadius: number;
5
5
  position: "fixed";
6
- top: string;
6
+ top: "0";
7
7
  zIndex: number;
8
8
  selectors: {
9
9
  "&:after": {
@@ -20,4 +20,19 @@ export declare const sortingHeader: import("@vanilla-extract/recipes/dist/declar
20
20
  };
21
21
  false: {};
22
22
  };
23
+ scrollParentIsWindow: {
24
+ true: {};
25
+ false: {};
26
+ };
27
+ __autoLayout: {
28
+ true: {
29
+ display: "table-row";
30
+ };
31
+ false: {
32
+ display: "table";
33
+ tableLayout: "fixed";
34
+ width: string;
35
+ };
36
+ };
23
37
  }>;
38
+ export declare const sortingHeaderSpacer: string;
@@ -1,7 +1,8 @@
1
1
  import * as React from "react";
2
2
  import type { ComponentProps, SortChangeHandler, SortedColumn } from "@sps-woodland/core";
3
- export declare function SortingHeader({ sort, onSortChange, children, className, pinSortingHeader, ...rest }: ComponentProps<{
3
+ export declare function SortingHeader({ sort, onSortChange, children, className, pinSortingHeader, __autoLayout, ...rest }: ComponentProps<{
4
4
  sort: SortedColumn[];
5
5
  onSortChange: SortChangeHandler;
6
6
  pinSortingHeader?: boolean;
7
+ __autoLayout?: boolean;
7
8
  }, HTMLDivElement>): React.ReactElement;
@@ -10,4 +10,20 @@ export declare const headerCell: import("@vanilla-extract/recipes/dist/declarati
10
10
  backgroundColor: string;
11
11
  };
12
12
  };
13
+ __autoLayout: {
14
+ true: {
15
+ textAlign: "left";
16
+ selectors: {
17
+ "&:first-child": {
18
+ borderTopLeftRadius: string;
19
+ borderBottomLeftRadius: string;
20
+ };
21
+ "&:last-child": {
22
+ borderTopRightRadius: string;
23
+ borderBottomRightRadius: string;
24
+ };
25
+ };
26
+ };
27
+ false: {};
28
+ };
13
29
  }>;
@@ -1,10 +1,11 @@
1
1
  import * as React from "react";
2
2
  import type { SortedColumn, SortChangeHandler, ComponentProps } from "@sps-woodland/core";
3
- export declare function SortingHeaderCell({ className, sortKey, sort, sortDisabled, onSortChange, onClick, children, style, widthPx, widthRem, ...rest }: ComponentProps<{
3
+ export declare function SortingHeaderCell({ className, sortKey, sort, sortDisabled, onSortChange, onClick, children, style, widthPx, widthRem, __autoLayout, ...rest }: ComponentProps<{
4
4
  sortKey?: string;
5
5
  sortDisabled?: boolean;
6
6
  sort?: SortedColumn[];
7
7
  onSortChange?: SortChangeHandler;
8
8
  widthPx?: number;
9
9
  widthRem?: number;
10
+ __autoLayout?: boolean;
10
11
  }, HTMLDivElement>): React.ReactElement;
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
+ ._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}._1crs4gl3{text-align:left}._1crs4gl3:first-child{border-top-left-radius:.25rem;border-bottom-left-radius:.25rem}._1crs4gl3:last-child{border-top-right-radius:.25rem;border-bottom-right-radius:.25rem}.sk81640{padding:0;border-radius:.25rem;vertical-align:bottom;cursor:pointer;background-color:#e9e9ea}.sk81641{border-radius:0;position:fixed;top:0;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%}.sk81645{display:table-row}.sk81646{display:table;table-layout:fixed;width:100%}.sk81647{top:3.75rem}.sk81648{height:1rem;background:transparent;border:0}
package/package.json CHANGED
@@ -1,7 +1,7 @@
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": "8.7.7",
4
+ "version": "8.8.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",
@@ -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": "8.7.7",
33
- "@sps-woodland/tokens": "8.7.7"
32
+ "@sps-woodland/core": "8.8.0",
33
+ "@sps-woodland/tokens": "8.8.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": "8.7.7",
43
- "@sps-woodland/tokens": "8.7.7"
42
+ "@sps-woodland/core": "8.8.0",
43
+ "@sps-woodland/tokens": "8.8.0"
44
44
  },
45
45
  "scripts": {
46
46
  "build": "pnpm run build:js && pnpm run build:types",