@bbl-digital/snorre 4.1.37 → 4.1.39

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.
@@ -0,0 +1,38 @@
1
+ import ButtonsFilter from '.';
2
+ const meta = {
3
+ title: 'v2/Core/ButtonsFilter',
4
+ component: ButtonsFilter
5
+ };
6
+ export default meta;
7
+ export const Default = {
8
+ name: 'Default',
9
+ args: {
10
+ values: ['One', 'Two', 'Three'],
11
+ disabled: false,
12
+ onChange: e => console.log(e)
13
+ }
14
+ };
15
+ export const Loading = {
16
+ name: 'Loading',
17
+ args: {
18
+ loading: true
19
+ }
20
+ };
21
+ export const ObjectValues = {
22
+ name: 'Object Values',
23
+ args: {
24
+ values: [{
25
+ label: 'One',
26
+ value: 15
27
+ }, {
28
+ label: 'Two',
29
+ value: 2
30
+ }, {
31
+ label: 'Three',
32
+ value: 5
33
+ }],
34
+ labelField: 'label',
35
+ valueField: 'value',
36
+ onChange: e => console.log(e)
37
+ }
38
+ };
@@ -0,0 +1,73 @@
1
+ /** @jsxImportSource @emotion/react */
2
+
3
+ import { useEffect, useMemo, useState } from 'react';
4
+ import Button from '../Button';
5
+ import { Wrapper } from './styles';
6
+ import Skeleton from '../../../core/Skeleton';
7
+ import { jsx as _jsx } from "@emotion/react/jsx-runtime";
8
+ const resolve = (value, field) => {
9
+ const valueIsObject = typeof value === 'object';
10
+ return valueIsObject ? value[field] : value;
11
+ };
12
+ const ButtonsFilter = ({
13
+ values,
14
+ disabled,
15
+ skeletons = 3,
16
+ labelField,
17
+ valueField,
18
+ loading,
19
+ onChange,
20
+ ...rest
21
+ }) => {
22
+ const [selected, setSelected] = useState(undefined);
23
+ const isEmpty = !values?.length;
24
+ const handleClick = value => {
25
+ setSelected(value);
26
+ onChange?.(value);
27
+ };
28
+ const resolvedValues = useMemo(() => {
29
+ if (!values) return [];
30
+ return values.map(value => ({
31
+ label: resolve(value, labelField),
32
+ value: resolve(value, valueField)
33
+ }));
34
+ }, [values, labelField, valueField]);
35
+ useEffect(() => {
36
+ if (loading || isEmpty || selected !== undefined) return;
37
+ const firstValue = resolve(values[0], valueField);
38
+ const selectedExists = resolvedValues.some(({
39
+ value
40
+ }) => value === selected);
41
+ if (!selectedExists) {
42
+ setSelected(firstValue);
43
+ onChange?.(firstValue);
44
+ }
45
+ }, [values, loading, selected, isEmpty, valueField, onChange]);
46
+ if (loading) return _jsx(Wrapper, {
47
+ children: Array.from({
48
+ length: skeletons
49
+ }).map((_, index) => _jsx(Skeleton, {
50
+ width: "100px",
51
+ height: "32px",
52
+ borderRadius: "100px",
53
+ rectangle: true
54
+ }, index))
55
+ });
56
+ if (isEmpty) return null;
57
+ return _jsx(Wrapper, {
58
+ children: resolvedValues.map(({
59
+ label,
60
+ value
61
+ }) => _jsx(Button, {
62
+ small: true,
63
+ title: label,
64
+ onClick: () => handleClick(value),
65
+ secondary: selected !== value,
66
+ "aria-pressed": selected === value,
67
+ disabled: disabled,
68
+ ...rest,
69
+ children: label
70
+ }, value))
71
+ });
72
+ };
73
+ export default ButtonsFilter;
@@ -0,0 +1,16 @@
1
+ import _styled from "@emotion/styled/base";
2
+ function _EMOTION_STRINGIFIED_CSS_ERROR__() { return "You have tried to stringify object returned from `css` function. It isn't supposed to be used directly (e.g. as value of the `className` prop), but rather handed to emotion so it can handle it (e.g. as value of `css` prop)."; }
3
+ export const Wrapper = /*#__PURE__*/_styled("div", process.env.NODE_ENV === "production" ? {
4
+ target: "e1djumss0"
5
+ } : {
6
+ target: "e1djumss0",
7
+ label: "Wrapper"
8
+ })(process.env.NODE_ENV === "production" ? {
9
+ name: "11impfd",
10
+ styles: "display:flex;gap:8px;margin-bottom:16px;flex-flow:wrap;width:100%"
11
+ } : {
12
+ name: "11impfd",
13
+ styles: "display:flex;gap:8px;margin-bottom:16px;flex-flow:wrap;width:100%",
14
+ map: "/*# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uL3NyYy9wYWNrYWdlcy92Mi9jb3JlL0J1dHRvbnNGaWx0ZXIvc3R5bGVzLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUVpQyIsImZpbGUiOiIuLi8uLi8uLi8uLi9zcmMvcGFja2FnZXMvdjIvY29yZS9CdXR0b25zRmlsdGVyL3N0eWxlcy50cyIsInNvdXJjZXNDb250ZW50IjpbImltcG9ydCBzdHlsZWQgZnJvbSAnQGVtb3Rpb24vc3R5bGVkJ1xuXG5leHBvcnQgY29uc3QgV3JhcHBlciA9IHN0eWxlZC5kaXZgXG4gIGRpc3BsYXk6IGZsZXg7XG4gIGdhcDogOHB4O1xuICBtYXJnaW4tYm90dG9tOiAxNnB4O1xuICBmbGV4LWZsb3c6IHdyYXA7XG4gIHdpZHRoOiAxMDAlO1xuYFxuIl19 */",
15
+ toString: _EMOTION_STRINGIFIED_CSS_ERROR__
16
+ });
package/esm/v2/index.js CHANGED
@@ -1,3 +1,4 @@
1
1
  import Chip from './core/Chip';
2
2
  import Button from './core/Button';
3
- export { Chip, Button };
3
+ import ButtonsFilter from './core/ButtonsFilter';
4
+ export { Chip, Button, ButtonsFilter };
@@ -1 +1 @@
1
- {"version":3,"file":"styles.d.ts","sourceRoot":"","sources":["../../../../src/packages/v2/core/Button/styles.ts"],"names":[],"mappings":"AAEA,OAAO,SAAS,MAAM,0BAA0B,CAAA;AAEhD,eAAO,MAAM,GAAG,mKAAuB,CAAA;AAEvC,QAAA,MAAM,MAAM;qBACO,SAAS;;uBAoCP,SAAS;mBAab,SAAS;kBAcV,SAAS;qBAsBN,SAAS;qBAqBT,SAAS;oBAgBV,SAAS;sBAcP,SAAS;oBAWX,MAAM;qBAGL,SAAS;;kBA6BZ,SAAS;;2BA8BA,SAAS;4BAIR,SAAS;;;CAalC,CAAA;AAED,eAAe,MAAM,CAAA;AAErB,OAAO,EAAE,MAAM,EAAE,CAAA"}
1
+ {"version":3,"file":"styles.d.ts","sourceRoot":"","sources":["../../../../src/packages/v2/core/Button/styles.ts"],"names":[],"mappings":"AAEA,OAAO,SAAS,MAAM,0BAA0B,CAAA;AAEhD,eAAO,MAAM,GAAG,mKAAuB,CAAA;AAEvC,QAAA,MAAM,MAAM;qBACO,SAAS;;uBAoCP,SAAS;mBAab,SAAS;kBAcV,SAAS;qBAsBN,SAAS;qBAuBT,SAAS;oBAgBV,SAAS;sBAcP,SAAS;oBAWX,MAAM;qBAGL,SAAS;;kBA6BZ,SAAS;;2BA8BA,SAAS;4BAIR,SAAS;;;CAalC,CAAA;AAED,eAAe,MAAM,CAAA;AAErB,OAAO,EAAE,MAAM,EAAE,CAAA"}