@janiscommerce/ui-web 1.5.0-beta.1 → 1.5.0-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.esm.js CHANGED
@@ -3,7 +3,6 @@ import React__default, { useState, useEffect, useRef, PureComponent, useMemo, us
3
3
  import styled$j, { css, createGlobalStyle, keyframes } from 'styled-components';
4
4
  import * as ReactDOM from 'react-dom';
5
5
  import ReactDOM__default from 'react-dom';
6
- import { useCollapse } from 'react-collapsed';
7
6
 
8
7
  function ownKeys$2(object, enumerableOnly) {
9
8
  var keys = Object.keys(object);
@@ -690,12 +689,12 @@ var hasOwnProperty_1 = Object.hasOwn || function hasOwn(it, key) {
690
689
 
691
690
  var uncurryThis$q = functionUncurryThis;
692
691
 
693
- var id = 0;
692
+ var id$1 = 0;
694
693
  var postfix = Math.random();
695
694
  var toString$b = uncurryThis$q(1.0.toString);
696
695
 
697
696
  var uid$2 = function (key) {
698
- return 'Symbol(' + (key === undefined ? '' : key) + ')_' + toString$b(++id + postfix, 36);
697
+ return 'Symbol(' + (key === undefined ? '' : key) + ')_' + toString$b(++id$1 + postfix, 36);
699
698
  };
700
699
 
701
700
  var global$H = global$T;
@@ -3780,7 +3779,7 @@ var FILE_HOST = {};
3780
3779
  var PATH_START = {};
3781
3780
  var PATH = {};
3782
3781
  var CANNOT_BE_A_BASE_URL_PATH = {};
3783
- var QUERY = {};
3782
+ var QUERY$1 = {};
3784
3783
  var FRAGMENT = {};
3785
3784
 
3786
3785
  var URLState = function (url, isBase, base) {
@@ -3933,7 +3932,7 @@ URLState.prototype = {
3933
3932
  url.port = base.port;
3934
3933
  url.path = arraySlice$4(base.path);
3935
3934
  url.query = '';
3936
- state = QUERY;
3935
+ state = QUERY$1;
3937
3936
  } else if (chr == '#') {
3938
3937
  url.username = base.username;
3939
3938
  url.password = base.password;
@@ -4069,7 +4068,7 @@ URLState.prototype = {
4069
4068
  url.host = base.host;
4070
4069
  url.path = arraySlice$4(base.path);
4071
4070
  url.query = '';
4072
- state = QUERY;
4071
+ state = QUERY$1;
4073
4072
  } else if (chr == '#') {
4074
4073
  url.host = base.host;
4075
4074
  url.path = arraySlice$4(base.path);
@@ -4127,7 +4126,7 @@ URLState.prototype = {
4127
4126
  if (chr != '/' && chr != '\\') continue;
4128
4127
  } else if (!stateOverride && chr == '?') {
4129
4128
  url.query = '';
4130
- state = QUERY;
4129
+ state = QUERY$1;
4131
4130
  } else if (!stateOverride && chr == '#') {
4132
4131
  url.fragment = '';
4133
4132
  state = FRAGMENT;
@@ -4166,7 +4165,7 @@ URLState.prototype = {
4166
4165
  }
4167
4166
  if (chr == '?') {
4168
4167
  url.query = '';
4169
- state = QUERY;
4168
+ state = QUERY$1;
4170
4169
  } else if (chr == '#') {
4171
4170
  url.fragment = '';
4172
4171
  state = FRAGMENT;
@@ -4178,7 +4177,7 @@ URLState.prototype = {
4178
4177
  case CANNOT_BE_A_BASE_URL_PATH:
4179
4178
  if (chr == '?') {
4180
4179
  url.query = '';
4181
- state = QUERY;
4180
+ state = QUERY$1;
4182
4181
  } else if (chr == '#') {
4183
4182
  url.fragment = '';
4184
4183
  state = FRAGMENT;
@@ -4186,7 +4185,7 @@ URLState.prototype = {
4186
4185
  url.path[0] += percentEncode(chr, C0ControlPercentEncodeSet);
4187
4186
  } break;
4188
4187
 
4189
- case QUERY:
4188
+ case QUERY$1:
4190
4189
  if (!stateOverride && chr == '#') {
4191
4190
  url.fragment = '';
4192
4191
  state = FRAGMENT;
@@ -4377,7 +4376,7 @@ URLState.prototype = {
4377
4376
  } else {
4378
4377
  if ('?' == charAt(search, 0)) search = stringSlice$1(search, 1);
4379
4378
  this.query = '';
4380
- this.parse(search, QUERY);
4379
+ this.parse(search, QUERY$1);
4381
4380
  }
4382
4381
  this.searchParams.update();
4383
4382
  },
@@ -35800,6 +35799,419 @@ var ProgressBar = function ProgressBar(_ref) {
35800
35799
  }));
35801
35800
  };
35802
35801
 
35802
+ function warning(condition, message) {
35803
+ }
35804
+
35805
+ /**
35806
+ * react-collapsed v4.2.0
35807
+ *
35808
+ * Copyright (c) 2019-2024, Rogin Farrer
35809
+ *
35810
+ * This source code is licensed under the MIT license found in the
35811
+ * LICENSE.md file in the root directory of this source tree.
35812
+ *
35813
+ * @license MIT
35814
+ */
35815
+ var CollapseError = class extends Error {
35816
+ constructor(message) {
35817
+ super(`react-collapsed: ${message}`);
35818
+ }
35819
+ };
35820
+ var collapseWarning = (...args) => {
35821
+ return warning(args[0], `[react-collapsed] -- ${args[1]}`);
35822
+ };
35823
+ function useEvent(callback) {
35824
+ const ref = useRef(callback);
35825
+ useEffect(() => {
35826
+ ref.current = callback;
35827
+ });
35828
+ return useCallback((...args) => ref.current?.(...args), []);
35829
+ }
35830
+ function useControlledState(value, defaultValue, callback) {
35831
+ const [state, setState] = useState(defaultValue);
35832
+ const initiallyControlled = useRef(typeof value !== "undefined");
35833
+ const effectiveValue = initiallyControlled.current ? value : state;
35834
+ const cb = useEvent(callback);
35835
+ const onChange = useCallback(
35836
+ (update) => {
35837
+ const setter = update;
35838
+ const newValue = typeof update === "function" ? setter(effectiveValue) : update;
35839
+ if (!initiallyControlled.current) {
35840
+ setState(newValue);
35841
+ }
35842
+ cb?.(newValue);
35843
+ },
35844
+ [cb, effectiveValue]
35845
+ );
35846
+ useEffect(() => {
35847
+ collapseWarning(
35848
+ !(initiallyControlled.current && value == null),
35849
+ "`isExpanded` state is changing from controlled to uncontrolled. useCollapse should not switch from controlled to uncontrolled (or vice versa). Decide between using a controlled or uncontrolled collapse for the lifetime of the component. Check the `isExpanded` prop."
35850
+ );
35851
+ collapseWarning(
35852
+ !(!initiallyControlled.current && value != null),
35853
+ "`isExpanded` state is changing from uncontrolled to controlled. useCollapse should not switch from uncontrolled to controlled (or vice versa). Decide between using a controlled or uncontrolled collapse for the lifetime of the component. Check the `isExpanded` prop."
35854
+ );
35855
+ }, [value]);
35856
+ return [effectiveValue, onChange];
35857
+ }
35858
+ var QUERY = "(prefers-reduced-motion: reduce)";
35859
+ function usePrefersReducedMotion() {
35860
+ const [prefersReducedMotion, setPrefersReducedMotion] = useState(false);
35861
+ useEffect(() => {
35862
+ if (typeof window === "undefined" || typeof window.matchMedia !== "function") {
35863
+ return;
35864
+ }
35865
+ const mediaQueryList = window.matchMedia(QUERY);
35866
+ setPrefersReducedMotion(mediaQueryList.matches);
35867
+ const listener = (event) => {
35868
+ setPrefersReducedMotion(event.matches);
35869
+ };
35870
+ if (mediaQueryList.addEventListener) {
35871
+ mediaQueryList.addEventListener("change", listener);
35872
+ return () => {
35873
+ mediaQueryList.removeEventListener("change", listener);
35874
+ };
35875
+ } else if (mediaQueryList.addListener) {
35876
+ mediaQueryList.addListener(listener);
35877
+ return () => {
35878
+ mediaQueryList.removeListener(listener);
35879
+ };
35880
+ }
35881
+ return void 0;
35882
+ }, []);
35883
+ return prefersReducedMotion;
35884
+ }
35885
+ var __useId = React["useId".toString()] || (() => void 0);
35886
+ function useReactId() {
35887
+ const id2 = __useId();
35888
+ return id2 ?? "";
35889
+ }
35890
+ var useIsomorphicLayoutEffect = typeof window !== "undefined" ? React.useLayoutEffect : React.useEffect;
35891
+ var serverHandoffComplete = false;
35892
+ var id = 0;
35893
+ var genId = () => ++id;
35894
+ function useUniqueId(idFromProps) {
35895
+ const initialId = idFromProps || (serverHandoffComplete ? genId() : null);
35896
+ const [id2, setId] = React.useState(initialId);
35897
+ useIsomorphicLayoutEffect(() => {
35898
+ if (id2 === null) {
35899
+ setId(genId());
35900
+ }
35901
+ }, []);
35902
+ React.useEffect(() => {
35903
+ if (serverHandoffComplete === false) {
35904
+ serverHandoffComplete = true;
35905
+ }
35906
+ }, []);
35907
+ return id2 != null ? String(id2) : void 0;
35908
+ }
35909
+ function useId(idOverride) {
35910
+ const reactId = useReactId();
35911
+ const uniqueId = useUniqueId(idOverride);
35912
+ if (typeof idOverride === "string") {
35913
+ return idOverride;
35914
+ }
35915
+ if (typeof reactId === "string") {
35916
+ return reactId;
35917
+ }
35918
+ return uniqueId;
35919
+ }
35920
+
35921
+ // src/utils/setAnimationTimeout.ts
35922
+ function setAnimationTimeout(callback, timeout) {
35923
+ const startTime = performance.now();
35924
+ const frame = {};
35925
+ function call() {
35926
+ frame.id = requestAnimationFrame((now) => {
35927
+ if (now - startTime > timeout) {
35928
+ callback();
35929
+ } else {
35930
+ call();
35931
+ }
35932
+ });
35933
+ }
35934
+ call();
35935
+ return frame;
35936
+ }
35937
+ function clearAnimationTimeout(frame) {
35938
+ if (frame.id)
35939
+ cancelAnimationFrame(frame.id);
35940
+ }
35941
+
35942
+ // src/utils/index.ts
35943
+ function getElementHeight(el) {
35944
+ if (!el?.current) {
35945
+ collapseWarning(
35946
+ true,
35947
+ `Was not able to find a ref to the collapse element via \`getCollapseProps\`. Ensure that the element exposes its \`ref\` prop. If it exposes the ref prop under a different name (like \`innerRef\`), use the \`refKey\` property to change it. Example:
35948
+
35949
+ const collapseProps = getCollapseProps({refKey: 'innerRef'})`
35950
+ );
35951
+ return 0;
35952
+ }
35953
+ return el.current.scrollHeight;
35954
+ }
35955
+ function getAutoHeightDuration(height) {
35956
+ if (!height || typeof height === "string") {
35957
+ return 0;
35958
+ }
35959
+ const constant = height / 36;
35960
+ return Math.round((4 + 15 * constant ** 0.25 + constant / 5) * 10);
35961
+ }
35962
+ function assignRef(ref, value) {
35963
+ if (ref == null)
35964
+ return;
35965
+ if (typeof ref === "function") {
35966
+ ref(value);
35967
+ } else {
35968
+ try {
35969
+ ref.current = value;
35970
+ } catch (error) {
35971
+ throw new CollapseError(`Cannot assign value "${value}" to ref "${ref}"`);
35972
+ }
35973
+ }
35974
+ }
35975
+ function mergeRefs(...refs) {
35976
+ if (refs.every((ref) => ref == null)) {
35977
+ return null;
35978
+ }
35979
+ return (node) => {
35980
+ refs.forEach((ref) => {
35981
+ assignRef(ref, node);
35982
+ });
35983
+ };
35984
+ }
35985
+ function usePaddingWarning(element) {
35986
+ let warn = (el) => {
35987
+ };
35988
+ {
35989
+ warn = (el) => {
35990
+ if (!el?.current) {
35991
+ return;
35992
+ }
35993
+ const { paddingTop, paddingBottom } = window.getComputedStyle(el.current);
35994
+ const hasPadding = paddingTop && paddingTop !== "0px" || paddingBottom && paddingBottom !== "0px";
35995
+ collapseWarning(
35996
+ !hasPadding,
35997
+ `Padding applied to the collapse element will cause the animation to break and not perform as expected. To fix, apply equivalent padding to the direct descendent of the collapse element. Example:
35998
+
35999
+ Before: <div {...getCollapseProps({style: {padding: 10}})}>{children}</div>
36000
+
36001
+ After: <div {...getCollapseProps()}>
36002
+ <div style={{padding: 10}}>
36003
+ {children}
36004
+ </div>
36005
+ </div>`
36006
+ );
36007
+ };
36008
+ }
36009
+ useEffect(() => {
36010
+ warn(element);
36011
+ }, [element]);
36012
+ }
36013
+
36014
+ // src/index.ts
36015
+ var useLayoutEffect2 = typeof window === "undefined" ? useEffect : useLayoutEffect;
36016
+ function useCollapse({
36017
+ duration,
36018
+ easing = "cubic-bezier(0.4, 0, 0.2, 1)",
36019
+ onTransitionStateChange: propOnTransitionStateChange = () => {
36020
+ },
36021
+ isExpanded: configIsExpanded,
36022
+ defaultExpanded = false,
36023
+ hasDisabledAnimation,
36024
+ id: id2,
36025
+ ...initialConfig
36026
+ } = {}) {
36027
+ const onTransitionStateChange = useEvent(propOnTransitionStateChange);
36028
+ const uniqueId = useId(id2 ? `${id2}` : void 0);
36029
+ const [isExpanded, setExpanded] = useControlledState(
36030
+ configIsExpanded,
36031
+ defaultExpanded
36032
+ );
36033
+ const prevExpanded = useRef(isExpanded);
36034
+ const [isAnimating, setIsAnimating] = useState(false);
36035
+ const prefersReducedMotion = usePrefersReducedMotion();
36036
+ const disableAnimation = hasDisabledAnimation ?? prefersReducedMotion;
36037
+ const frameId = useRef();
36038
+ const endFrameId = useRef();
36039
+ const collapseElRef = useRef(null);
36040
+ const [toggleEl, setToggleEl] = useState(null);
36041
+ usePaddingWarning(collapseElRef);
36042
+ const collapsedHeight = `${initialConfig.collapsedHeight || 0}px`;
36043
+ function setStyles(newStyles) {
36044
+ if (!collapseElRef.current)
36045
+ return;
36046
+ const target = collapseElRef.current;
36047
+ for (const property in newStyles) {
36048
+ const value = newStyles[property];
36049
+ if (value) {
36050
+ target.style[property] = value;
36051
+ } else {
36052
+ target.style.removeProperty(property);
36053
+ }
36054
+ }
36055
+ }
36056
+ useLayoutEffect2(() => {
36057
+ const collapse = collapseElRef.current;
36058
+ if (!collapse)
36059
+ return;
36060
+ if (isExpanded === prevExpanded.current)
36061
+ return;
36062
+ prevExpanded.current = isExpanded;
36063
+ function getDuration(height) {
36064
+ if (disableAnimation) {
36065
+ return 0;
36066
+ }
36067
+ return duration ?? getAutoHeightDuration(height);
36068
+ }
36069
+ const getTransitionStyles = (height) => `height ${getDuration(height)}ms ${easing}`;
36070
+ const setTransitionEndTimeout = (duration2) => {
36071
+ function endTransition() {
36072
+ if (isExpanded) {
36073
+ setStyles({
36074
+ height: "",
36075
+ overflow: "",
36076
+ transition: "",
36077
+ display: ""
36078
+ });
36079
+ onTransitionStateChange("expandEnd");
36080
+ } else {
36081
+ setStyles({ transition: "" });
36082
+ onTransitionStateChange("collapseEnd");
36083
+ }
36084
+ setIsAnimating(false);
36085
+ }
36086
+ if (endFrameId.current) {
36087
+ clearAnimationTimeout(endFrameId.current);
36088
+ }
36089
+ endFrameId.current = setAnimationTimeout(endTransition, duration2);
36090
+ };
36091
+ setIsAnimating(true);
36092
+ if (isExpanded) {
36093
+ frameId.current = requestAnimationFrame(() => {
36094
+ onTransitionStateChange("expandStart");
36095
+ setStyles({
36096
+ display: "block",
36097
+ overflow: "hidden",
36098
+ height: collapsedHeight
36099
+ });
36100
+ frameId.current = requestAnimationFrame(() => {
36101
+ onTransitionStateChange("expanding");
36102
+ const height = getElementHeight(collapseElRef);
36103
+ setTransitionEndTimeout(getDuration(height));
36104
+ if (collapseElRef.current) {
36105
+ collapseElRef.current.style.transition = getTransitionStyles(height);
36106
+ collapseElRef.current.style.height = `${height}px`;
36107
+ }
36108
+ });
36109
+ });
36110
+ } else {
36111
+ frameId.current = requestAnimationFrame(() => {
36112
+ onTransitionStateChange("collapseStart");
36113
+ const height = getElementHeight(collapseElRef);
36114
+ setTransitionEndTimeout(getDuration(height));
36115
+ setStyles({
36116
+ transition: getTransitionStyles(height),
36117
+ height: `${height}px`
36118
+ });
36119
+ frameId.current = requestAnimationFrame(() => {
36120
+ onTransitionStateChange("collapsing");
36121
+ setStyles({
36122
+ height: collapsedHeight,
36123
+ overflow: "hidden"
36124
+ });
36125
+ });
36126
+ });
36127
+ }
36128
+ return () => {
36129
+ if (frameId.current)
36130
+ cancelAnimationFrame(frameId.current);
36131
+ if (endFrameId.current)
36132
+ clearAnimationTimeout(endFrameId.current);
36133
+ };
36134
+ }, [
36135
+ isExpanded,
36136
+ collapsedHeight,
36137
+ disableAnimation,
36138
+ duration,
36139
+ easing,
36140
+ onTransitionStateChange
36141
+ ]);
36142
+ return {
36143
+ isExpanded,
36144
+ setExpanded,
36145
+ getToggleProps(args) {
36146
+ const { disabled, onClick, refKey, ...rest } = {
36147
+ refKey: "ref",
36148
+ onClick() {
36149
+ },
36150
+ disabled: false,
36151
+ ...args
36152
+ };
36153
+ const isButton = toggleEl ? toggleEl.tagName === "BUTTON" : void 0;
36154
+ const theirRef = args?.[refKey || "ref"];
36155
+ const props = {
36156
+ id: `react-collapsed-toggle-${uniqueId}`,
36157
+ "aria-controls": `react-collapsed-panel-${uniqueId}`,
36158
+ "aria-expanded": isExpanded,
36159
+ onClick(evt) {
36160
+ if (disabled)
36161
+ return;
36162
+ onClick?.(evt);
36163
+ setExpanded((n) => !n);
36164
+ },
36165
+ [refKey || "ref"]: mergeRefs(theirRef, setToggleEl)
36166
+ };
36167
+ const buttonProps = {
36168
+ type: "button",
36169
+ disabled: disabled ? true : void 0
36170
+ };
36171
+ const fakeButtonProps = {
36172
+ "aria-disabled": disabled ? true : void 0,
36173
+ role: "button",
36174
+ tabIndex: disabled ? -1 : 0
36175
+ };
36176
+ if (isButton === false) {
36177
+ return { ...props, ...fakeButtonProps, ...rest };
36178
+ } else if (isButton === true) {
36179
+ return { ...props, ...buttonProps, ...rest };
36180
+ } else {
36181
+ return {
36182
+ ...props,
36183
+ ...buttonProps,
36184
+ ...fakeButtonProps,
36185
+ ...rest
36186
+ };
36187
+ }
36188
+ },
36189
+ getCollapseProps(args) {
36190
+ const { style, refKey } = { refKey: "ref", style: {}, ...args };
36191
+ const theirRef = args?.[refKey || "ref"];
36192
+ return {
36193
+ id: `react-collapsed-panel-${uniqueId}`,
36194
+ "aria-hidden": !isExpanded,
36195
+ "aria-labelledby": `react-collapsed-toggle-${uniqueId}`,
36196
+ role: "region",
36197
+ ...args,
36198
+ [refKey || "ref"]: mergeRefs(collapseElRef, theirRef),
36199
+ style: {
36200
+ boxSizing: "border-box",
36201
+ ...!isAnimating && !isExpanded ? {
36202
+ // collapsed and not animating
36203
+ display: collapsedHeight === "0px" ? "none" : "block",
36204
+ height: collapsedHeight,
36205
+ overflow: "hidden"
36206
+ } : {},
36207
+ // additional styles passed, e.g. getCollapseProps({style: {}})
36208
+ ...style
36209
+ }
36210
+ };
36211
+ }
36212
+ };
36213
+ }
36214
+
35803
36215
  var Wrapper = styled$j.div.withConfig({
35804
36216
  displayName: "styles__Wrapper",
35805
36217
  componentId: "sc-mlx2bu-0"