@bit.rhplus/ui.antd.state-select 0.0.1

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,8 @@
1
+ export default StateSelect;
2
+ declare function StateSelect({ states, value, onChange, style, ...rest }: {
3
+ [x: string]: any;
4
+ states: any;
5
+ value: any;
6
+ onChange: any;
7
+ style: any;
8
+ }): import("react/jsx-runtime").JSX.Element;
package/dist/index.js ADDED
@@ -0,0 +1,42 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ /* eslint-disable */
3
+ import React, { useMemo } from 'react';
4
+ import Select from 'antd/es/select';
5
+ import Linq from '@bit.rhplus/linq';
6
+ const badgeStyle = (color, textColor) => ({
7
+ display: 'inline-block',
8
+ backgroundColor: color || '#666',
9
+ color: textColor || '#fff',
10
+ borderRadius: 12,
11
+ padding: '2px 12px',
12
+ fontSize: 13,
13
+ lineHeight: '20px',
14
+ whiteSpace: 'nowrap',
15
+ });
16
+ const StateSelect = ({ states, value, onChange, style, ...rest }) => {
17
+ const options = useMemo(() => Linq.from(states || [])
18
+ .where((w) => w.visible)
19
+ .orderBy((o) => o.ordering)
20
+ .select((s) => ({
21
+ value: s.id,
22
+ label: s.translatedName,
23
+ color: s.color,
24
+ textColor: s.textColor,
25
+ }))
26
+ .toArray(), [states]);
27
+ const stateMap = useMemo(() => {
28
+ const map = {};
29
+ for (const opt of options) {
30
+ map[opt.value] = opt;
31
+ }
32
+ return map;
33
+ }, [options]);
34
+ return (_jsx(Select, { value: value, onChange: onChange, options: options, style: { width: '100%', ...style }, placeholder: "Vyberte stav", optionRender: (option) => (_jsx("span", { style: badgeStyle(option.data.color, option.data.textColor), children: option.data.label })), labelRender: ({ value: val }) => {
35
+ const state = stateMap[val];
36
+ if (!state)
37
+ return val;
38
+ return (_jsx("span", { style: badgeStyle(state.color, state.textColor), children: state.label }));
39
+ }, ...rest }));
40
+ };
41
+ export default StateSelect;
42
+ //# sourceMappingUR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C5B,MAAM,GAAG,GAAG,EAAE,CAAC;QACf,KAAK,MAAM,GAAG,IAAI,OAAO,EAAE,CAAC;YAC1B,GAAG,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,GAAG,CAAC;QACvB,CAAC;QACD,OAAO,GAAG,CAAC;IACb,CAAC,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC;IAEd,OAAO,CACL,KAAC,MAAM,IACL,KAAK,EAAE,KAAK,EACZ,QAAQ,EAAE,QAAQ,EAClB,OAAO,EAAE,OAAO,EAChB,KAAK,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,KAAK,EAAE,EAClC,WAAW,EAAC,cAAc,EAC1B,YAAY,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,CACxB,eAAM,KAAK,EAAE,UAAU,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,EAAE,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,YAC9D,MAAM,CAAC,IAAI,CAAC,KAAK,GACb,CACR,EACD,WAAW,EAAE,CAAC,EAAE,KAAK,EAAE,GAAG,EAAE,EAAE,EAAE;YAC9B,MAAM,KAAK,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAC;YAC5B,IAAI,CAAC,KAAK;gBAAE,OAAO,GAAG,CAAC;YACvB,OAAO,CACL,eAAM,KAAK,EAAE,UAAU,CAAC,KAAK,CAAC,KAAK,EAAE,KAAK,CAAC,SAAS,CAAC,YAClD,KAAK,CAAC,KAAK,GACP,CACR,CAAC;QACJ,CAAC,KACG,IAAI,GACR,CACH,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,WAAW,CAAC"}
@@ -0,0 +1,7 @@
1
+ ;
2
+ ;
3
+
4
+ export const compositions = [];
5
+ export const overview = [];
6
+
7
+ export const compositions_metadata = {"compositions":[]};
package/index.jsx ADDED
@@ -0,0 +1,67 @@
1
+ /* eslint-disable */
2
+ import React, { useMemo } from 'react';
3
+ import Select from 'antd/es/select';
4
+ import Linq from '@bit.rhplus/linq';
5
+
6
+ const badgeStyle = (color, textColor) => ({
7
+ display: 'inline-block',
8
+ backgroundColor: color || '#666',
9
+ color: textColor || '#fff',
10
+ borderRadius: 12,
11
+ padding: '2px 12px',
12
+ fontSize: 13,
13
+ lineHeight: '20px',
14
+ whiteSpace: 'nowrap',
15
+ });
16
+
17
+ const StateSelect = ({ states, value, onChange, style, ...rest }) => {
18
+
19
+ const options = useMemo(() =>
20
+ Linq.from(states || [])
21
+ .where((w) => w.visible)
22
+ .orderBy((o) => o.ordering)
23
+ .select((s) => ({
24
+ value: s.id,
25
+ label: s.translatedName,
26
+ color: s.color,
27
+ textColor: s.textColor,
28
+ }))
29
+ .toArray(),
30
+ [states]
31
+ );
32
+
33
+ const stateMap = useMemo(() => {
34
+ const map = {};
35
+ for (const opt of options) {
36
+ map[opt.value] = opt;
37
+ }
38
+ return map;
39
+ }, [options]);
40
+
41
+ return (
42
+ <Select
43
+ value={value}
44
+ onChange={onChange}
45
+ options={options}
46
+ style={{ width: '100%', ...style }}
47
+ placeholder="Vyberte stav"
48
+ optionRender={(option) => (
49
+ <span style={badgeStyle(option.data.color, option.data.textColor)}>
50
+ {option.data.label}
51
+ </span>
52
+ )}
53
+ labelRender={({ value: val }) => {
54
+ const state = stateMap[val];
55
+ if (!state) return val;
56
+ return (
57
+ <span style={badgeStyle(state.color, state.textColor)}>
58
+ {state.label}
59
+ </span>
60
+ );
61
+ }}
62
+ {...rest}
63
+ />
64
+ );
65
+ };
66
+
67
+ export default StateSelect;
package/package.json ADDED
@@ -0,0 +1,29 @@
1
+ {
2
+ "name": "@bit.rhplus/ui.antd.state-select",
3
+ "version": "0.0.1",
4
+ "main": "dist/index.js",
5
+ "componentId": {
6
+ "name": "ui/antd/state-select",
7
+ "version": "0.0.1",
8
+ "scope": "remote-scope"
9
+ },
10
+ "dependencies": {
11
+ "antd": "^5.20.6",
12
+ "@bit.rhplus/linq": "0.0.11"
13
+ },
14
+ "devDependencies": {
15
+ "@bitdev/react.react-env": "5.0.5"
16
+ },
17
+ "peerDependencies": {
18
+ "react": "^17.0.0 || ^18.0.0 || ^19.0.0"
19
+ },
20
+ "license": "SEE LICENSE IN UNLICENSED",
21
+ "optionalDependencies": {},
22
+ "peerDependenciesMeta": {},
23
+ "type": "module",
24
+ "private": false,
25
+ "publishConfig": {
26
+ "scope": "@bit.rhplus",
27
+ "registry": "https://registry.npmjs.org/"
28
+ }
29
+ }
@@ -0,0 +1,43 @@
1
+ declare module '*.png' {
2
+ const value: any;
3
+ export = value;
4
+ }
5
+ declare module '*.svg' {
6
+ import type { FunctionComponent, SVGProps } from 'react';
7
+
8
+ export const ReactComponent: FunctionComponent<
9
+ SVGProps<SVGSVGElement> & { title?: string }
10
+ >;
11
+ const src: string;
12
+ export default src;
13
+ }
14
+
15
+ // @TODO Gilad
16
+ declare module '*.jpg' {
17
+ const value: any;
18
+ export = value;
19
+ }
20
+ declare module '*.jpeg' {
21
+ const value: any;
22
+ export = value;
23
+ }
24
+ declare module '*.gif' {
25
+ const value: any;
26
+ export = value;
27
+ }
28
+ declare module '*.bmp' {
29
+ const value: any;
30
+ export = value;
31
+ }
32
+ declare module '*.otf' {
33
+ const value: any;
34
+ export = value;
35
+ }
36
+ declare module '*.woff' {
37
+ const value: any;
38
+ export = value;
39
+ }
40
+ declare module '*.woff2' {
41
+ const value: any;
42
+ export = value;
43
+ }
package/types/env.d.ts ADDED
@@ -0,0 +1,15 @@
1
+ /// <reference types="vite/client" />
2
+
3
+ export type ImportMetaEnv = Record<string, string>;
4
+
5
+ interface ImportMeta {
6
+ readonly env: ImportMetaEnv
7
+ }
8
+
9
+ declare global {
10
+ namespace NodeJS {
11
+ interface ProcessEnv {
12
+ [key: string]: string;
13
+ }
14
+ }
15
+ }
@@ -0,0 +1,42 @@
1
+ declare module '*.module.css' {
2
+ const classes: { readonly [key: string]: string };
3
+ export default classes;
4
+ }
5
+ declare module '*.module.scss' {
6
+ const classes: { readonly [key: string]: string };
7
+ export default classes;
8
+ }
9
+ declare module '*.module.sass' {
10
+ const classes: { readonly [key: string]: string };
11
+ export default classes;
12
+ }
13
+
14
+ declare module '*.module.less' {
15
+ const classes: { readonly [key: string]: string };
16
+ export default classes;
17
+ }
18
+
19
+ declare module '*.less' {
20
+ const classes: { readonly [key: string]: string };
21
+ export default classes;
22
+ }
23
+
24
+ declare module '*.css' {
25
+ const classes: { readonly [key: string]: string };
26
+ export default classes;
27
+ }
28
+
29
+ declare module '*.sass' {
30
+ const classes: { readonly [key: string]: string };
31
+ export default classes;
32
+ }
33
+
34
+ declare module '*.scss' {
35
+ const classes: { readonly [key: string]: string };
36
+ export default classes;
37
+ }
38
+
39
+ declare module '*.mdx' {
40
+ const component: any;
41
+ export default component;
42
+ }