@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.
- package/esm/v2/core/Button/styles.js +19 -19
- package/esm/v2/core/ButtonsFilter/ButtonsFilter.stories.js +38 -0
- package/esm/v2/core/ButtonsFilter/index.js +73 -0
- package/esm/v2/core/ButtonsFilter/styles.js +16 -0
- package/esm/v2/index.js +2 -1
- package/lib/v2/core/Button/styles.d.ts.map +1 -1
- package/lib/v2/core/Button/styles.js +19 -19
- package/lib/v2/core/ButtonsFilter/ButtonsFilter.stories.d.ts +9 -0
- package/lib/v2/core/ButtonsFilter/ButtonsFilter.stories.d.ts.map +1 -0
- package/lib/v2/core/ButtonsFilter/ButtonsFilter.stories.js +38 -0
- package/lib/v2/core/ButtonsFilter/index.d.ts +14 -0
- package/lib/v2/core/ButtonsFilter/index.d.ts.map +1 -0
- package/lib/v2/core/ButtonsFilter/index.js +73 -0
- package/lib/v2/core/ButtonsFilter/styles.d.ts +5 -0
- package/lib/v2/core/ButtonsFilter/styles.d.ts.map +1 -0
- package/lib/v2/core/ButtonsFilter/styles.js +16 -0
- package/lib/v2/index.d.ts +2 -1
- package/lib/v2/index.d.ts.map +1 -1
- package/lib/v2/index.js +2 -1
- package/package.json +1 -1
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Meta, StoryObj } from '@storybook/react/*';
|
|
2
|
+
import ButtonsFilter from '.';
|
|
3
|
+
declare const meta: Meta<typeof ButtonsFilter>;
|
|
4
|
+
export default meta;
|
|
5
|
+
type Story = StoryObj<typeof ButtonsFilter>;
|
|
6
|
+
export declare const Default: Story;
|
|
7
|
+
export declare const Loading: Story;
|
|
8
|
+
export declare const ObjectValues: Story;
|
|
9
|
+
//# sourceMappingURL=ButtonsFilter.stories.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ButtonsFilter.stories.d.ts","sourceRoot":"","sources":["../../../../src/packages/v2/core/ButtonsFilter/ButtonsFilter.stories.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAA;AACnD,OAAO,aAAa,MAAM,GAAG,CAAA;AAE7B,QAAA,MAAM,IAAI,EAAE,IAAI,CAAC,OAAO,aAAa,CAGpC,CAAA;AAED,eAAe,IAAI,CAAA;AAEnB,KAAK,KAAK,GAAG,QAAQ,CAAC,OAAO,aAAa,CAAC,CAAA;AAE3C,eAAO,MAAM,OAAO,EAAE,KAOrB,CAAA;AAED,eAAO,MAAM,OAAO,EAAE,KAKrB,CAAA;AAED,eAAO,MAAM,YAAY,EAAE,KAY1B,CAAA"}
|
|
@@ -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,14 @@
|
|
|
1
|
+
/** @jsxImportSource @emotion/react */
|
|
2
|
+
import { AriaAttributes } from 'react';
|
|
3
|
+
interface IProps extends AriaAttributes {
|
|
4
|
+
values: Array<string | Record<string, any>>;
|
|
5
|
+
labelField: string;
|
|
6
|
+
valueField: string;
|
|
7
|
+
disabled?: boolean;
|
|
8
|
+
loading?: boolean;
|
|
9
|
+
skeletons?: number;
|
|
10
|
+
onChange?: (value: string) => void;
|
|
11
|
+
}
|
|
12
|
+
declare const ButtonsFilter: React.FC<IProps>;
|
|
13
|
+
export default ButtonsFilter;
|
|
14
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/packages/v2/core/ButtonsFilter/index.tsx"],"names":[],"mappings":"AAAA,sCAAsC;AAEtC,OAAO,EAAE,cAAc,EAAgC,MAAM,OAAO,CAAA;AAKpE,UAAU,MAAO,SAAQ,cAAc;IACrC,MAAM,EAAE,KAAK,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,CAAA;IAC3C,UAAU,EAAE,MAAM,CAAA;IAClB,UAAU,EAAE,MAAM,CAAA;IAClB,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAA;CACnC;AAMD,QAAA,MAAM,aAAa,EAAE,KAAK,CAAC,EAAE,CAAC,MAAM,CA2EnC,CAAA;AAED,eAAe,aAAa,CAAA"}
|
|
@@ -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,5 @@
|
|
|
1
|
+
export declare const Wrapper: import("@emotion/styled").StyledComponent<{
|
|
2
|
+
theme?: import("@emotion/react").Theme;
|
|
3
|
+
as?: React.ElementType;
|
|
4
|
+
}, import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, {}>;
|
|
5
|
+
//# sourceMappingURL=styles.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"styles.d.ts","sourceRoot":"","sources":["../../../../src/packages/v2/core/ButtonsFilter/styles.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,OAAO;;eAO0b,WAAW;yGADxd,CAAA"}
|
|
@@ -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/lib/v2/index.d.ts
CHANGED
package/lib/v2/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/packages/v2/index.tsx"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,aAAa,CAAA;AAC9B,OAAO,MAAM,MAAM,eAAe,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/packages/v2/index.tsx"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,aAAa,CAAA;AAC9B,OAAO,MAAM,MAAM,eAAe,CAAA;AAClC,OAAO,aAAa,MAAM,sBAAsB,CAAA;AAEhD,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,aAAa,EAAE,CAAA"}
|
package/lib/v2/index.js
CHANGED