@cyber-harbour/ui 1.0.47 → 1.0.48
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.d.mts +27 -1
- package/dist/index.d.ts +27 -1
- package/dist/index.js +166 -113
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +135 -82
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/Core/Tag/Tag.tsx +133 -0
- package/src/Core/Tag/index.ts +1 -0
- package/src/Core/index.ts +1 -0
- package/src/Theme/themes/dark.ts +30 -0
- package/src/Theme/themes/light.ts +30 -0
- package/src/Theme/types.ts +12 -0
- package/src/Theme/utils.ts +14 -0
package/package.json
CHANGED
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import styled from 'styled-components';
|
|
3
|
+
import { FabricComponent, createComponent, TagVariant, TagColor, hexToRgba } from '../../Theme';
|
|
4
|
+
import { CrossIcon } from '../IconComponents';
|
|
5
|
+
|
|
6
|
+
type TagProps = FabricComponent<{
|
|
7
|
+
children?: any;
|
|
8
|
+
variant?: TagVariant;
|
|
9
|
+
color?: TagColor;
|
|
10
|
+
className?: string;
|
|
11
|
+
icon?: any;
|
|
12
|
+
disabled?: boolean;
|
|
13
|
+
onClick?: () => void;
|
|
14
|
+
onDelete?: () => void;
|
|
15
|
+
}> &
|
|
16
|
+
Omit<React.HTMLAttributes<HTMLDivElement>, 'children'>;
|
|
17
|
+
|
|
18
|
+
export const Tag = ({
|
|
19
|
+
children,
|
|
20
|
+
variant = 'fill',
|
|
21
|
+
color = 'default',
|
|
22
|
+
className,
|
|
23
|
+
disabled,
|
|
24
|
+
icon,
|
|
25
|
+
onClick,
|
|
26
|
+
onDelete,
|
|
27
|
+
...props
|
|
28
|
+
}: TagProps) => {
|
|
29
|
+
return (
|
|
30
|
+
<StyledContainer
|
|
31
|
+
$variant={variant}
|
|
32
|
+
$color={color}
|
|
33
|
+
$clickable={!!onClick && !disabled}
|
|
34
|
+
onClick={!disabled ? onClick : undefined}
|
|
35
|
+
className={className}
|
|
36
|
+
{...props}
|
|
37
|
+
>
|
|
38
|
+
{!!children && <Content>{children}</Content>}
|
|
39
|
+
{!!onDelete && !disabled && (
|
|
40
|
+
<DeleteButton
|
|
41
|
+
aria-label="delete"
|
|
42
|
+
onClick={(e) => {
|
|
43
|
+
e.stopPropagation();
|
|
44
|
+
onDelete();
|
|
45
|
+
}}
|
|
46
|
+
>
|
|
47
|
+
<CrossIcon />
|
|
48
|
+
</DeleteButton>
|
|
49
|
+
)}
|
|
50
|
+
</StyledContainer>
|
|
51
|
+
);
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
type StyledProps = {
|
|
55
|
+
$variant: TagVariant;
|
|
56
|
+
$color: TagColor;
|
|
57
|
+
$clickable: boolean;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
const Content = styled.span`
|
|
61
|
+
display: inline-flex;
|
|
62
|
+
align-items: center;
|
|
63
|
+
justify-content: center;
|
|
64
|
+
min-width: 0;
|
|
65
|
+
|
|
66
|
+
font-size: 14px;
|
|
67
|
+
line-height: 16px;
|
|
68
|
+
`;
|
|
69
|
+
|
|
70
|
+
const DeleteButton = styled.button`
|
|
71
|
+
border: none;
|
|
72
|
+
outline: none;
|
|
73
|
+
background-color: transparent;
|
|
74
|
+
cursor: pointer;
|
|
75
|
+
color: currentColor;
|
|
76
|
+
transition: color 0.2s ease;
|
|
77
|
+
svg {
|
|
78
|
+
width: 10px;
|
|
79
|
+
height: 10px;
|
|
80
|
+
fill: currentColor;
|
|
81
|
+
}
|
|
82
|
+
`;
|
|
83
|
+
|
|
84
|
+
const StyledContainer = styled(createComponent<StyledProps>('div'))(
|
|
85
|
+
({
|
|
86
|
+
theme,
|
|
87
|
+
$variant,
|
|
88
|
+
$color,
|
|
89
|
+
$clickable,
|
|
90
|
+
py = theme.tag[$variant].paddingBlock,
|
|
91
|
+
px = theme.tag[$variant].paddingInline,
|
|
92
|
+
}) => {
|
|
93
|
+
const color = theme.tag[$variant].color[$color] || $color;
|
|
94
|
+
return `
|
|
95
|
+
display: inline-flex;
|
|
96
|
+
align-items: center;
|
|
97
|
+
justify-content: center;
|
|
98
|
+
padding-block: 0;
|
|
99
|
+
padding-inline: 0;
|
|
100
|
+
min-width: 0;
|
|
101
|
+
border-width: ${theme.tag[$variant].borderWidth};
|
|
102
|
+
border-style: solid;
|
|
103
|
+
border-color: ${color};
|
|
104
|
+
border-radius: ${theme.tag[$variant].borderRadius};
|
|
105
|
+
background-color: ${$variant === 'outlined' ? theme.colors.background : hexToRgba(color, 0.05)};
|
|
106
|
+
color: ${color};
|
|
107
|
+
|
|
108
|
+
${Content} {
|
|
109
|
+
padding-block: ${py};
|
|
110
|
+
padding-inline: ${px};
|
|
111
|
+
color: ${color};
|
|
112
|
+
${
|
|
113
|
+
$clickable
|
|
114
|
+
? `
|
|
115
|
+
cursor: pointer;
|
|
116
|
+
transition: color 0.2s ease;
|
|
117
|
+
&:hover {
|
|
118
|
+
color: ${hexToRgba(color, 0.7)};
|
|
119
|
+
}
|
|
120
|
+
`
|
|
121
|
+
: ''
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
${DeleteButton} {
|
|
125
|
+
padding-right: ${px};
|
|
126
|
+
padding-block: ${py};
|
|
127
|
+
&:hover {
|
|
128
|
+
color: ${hexToRgba(color, 0.7)};
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
`;
|
|
132
|
+
}
|
|
133
|
+
);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './Tag';
|
package/src/Core/index.ts
CHANGED
package/src/Theme/themes/dark.ts
CHANGED
|
@@ -706,6 +706,36 @@ export const darkThemePx: Theme = {
|
|
|
706
706
|
foreground: '#99989C',
|
|
707
707
|
background: '#535353',
|
|
708
708
|
},
|
|
709
|
+
tag: {
|
|
710
|
+
outlined: {
|
|
711
|
+
borderRadius: 50,
|
|
712
|
+
paddingBlock: 5,
|
|
713
|
+
paddingInline: 10,
|
|
714
|
+
borderWidth: 1,
|
|
715
|
+
color: {
|
|
716
|
+
default: '#99989C',
|
|
717
|
+
primary: '#3991FA',
|
|
718
|
+
error: '#D82323',
|
|
719
|
+
success: '#38A473',
|
|
720
|
+
warning: '#DEB839',
|
|
721
|
+
disabled: '#ebebeb',
|
|
722
|
+
},
|
|
723
|
+
},
|
|
724
|
+
fill: {
|
|
725
|
+
borderRadius: 4,
|
|
726
|
+
paddingBlock: 5,
|
|
727
|
+
paddingInline: 10,
|
|
728
|
+
borderWidth: 0,
|
|
729
|
+
color: {
|
|
730
|
+
default: '#99989C',
|
|
731
|
+
primary: '#3991FA',
|
|
732
|
+
error: '#D82323',
|
|
733
|
+
success: '#38A473',
|
|
734
|
+
warning: '#DEB839',
|
|
735
|
+
disabled: '#ebebeb',
|
|
736
|
+
},
|
|
737
|
+
},
|
|
738
|
+
},
|
|
709
739
|
};
|
|
710
740
|
|
|
711
741
|
export const darkTheme = convertPaletteToRem(darkThemePx, darkThemePx.baseSize) as DefaultTheme;
|
|
@@ -705,6 +705,36 @@ export const lightThemePx: Theme = {
|
|
|
705
705
|
foreground: '#E2E2E2E2',
|
|
706
706
|
background: '#F3F3F3',
|
|
707
707
|
},
|
|
708
|
+
tag: {
|
|
709
|
+
outlined: {
|
|
710
|
+
borderRadius: 50,
|
|
711
|
+
paddingBlock: 5,
|
|
712
|
+
paddingInline: 10,
|
|
713
|
+
borderWidth: 1,
|
|
714
|
+
color: {
|
|
715
|
+
default: '#535353',
|
|
716
|
+
primary: '#0042EC',
|
|
717
|
+
error: '#D82323',
|
|
718
|
+
success: '#38A473',
|
|
719
|
+
warning: '#DEB839',
|
|
720
|
+
disabled: '#ebebeb',
|
|
721
|
+
},
|
|
722
|
+
},
|
|
723
|
+
fill: {
|
|
724
|
+
borderRadius: 4,
|
|
725
|
+
paddingBlock: 5,
|
|
726
|
+
paddingInline: 10,
|
|
727
|
+
borderWidth: 0,
|
|
728
|
+
color: {
|
|
729
|
+
default: '#535353',
|
|
730
|
+
primary: '#0042EC',
|
|
731
|
+
error: '#D82323',
|
|
732
|
+
success: '#38A473',
|
|
733
|
+
warning: '#DEB839',
|
|
734
|
+
disabled: '#ebebeb',
|
|
735
|
+
},
|
|
736
|
+
},
|
|
737
|
+
},
|
|
708
738
|
};
|
|
709
739
|
|
|
710
740
|
export const lightTheme = convertPaletteToRem(lightThemePx, lightThemePx.baseSize) as DefaultTheme;
|
package/src/Theme/types.ts
CHANGED
|
@@ -10,6 +10,9 @@ export type InputVariant = 'outlined' | 'empty';
|
|
|
10
10
|
export type InputState = 'default' | 'focus' | 'error' | 'disabled';
|
|
11
11
|
export type InputSize = 'empty' | 'small' | 'medium';
|
|
12
12
|
|
|
13
|
+
export type TagVariant = 'fill' | 'outlined';
|
|
14
|
+
export type TagColor = 'default' | 'primary' | 'error' | 'warning' | 'success' | 'disabled' | string;
|
|
15
|
+
|
|
13
16
|
// Типи для spacing та breakpoints
|
|
14
17
|
export type Breakpoint = 'xs' | 's' | 'm' | 'l' | 'xl';
|
|
15
18
|
|
|
@@ -57,6 +60,14 @@ export type InputSizeStyle = {
|
|
|
57
60
|
lineHeight: number;
|
|
58
61
|
};
|
|
59
62
|
|
|
63
|
+
export type TagElementStyle = {
|
|
64
|
+
paddingInline: number | string;
|
|
65
|
+
paddingBlock: number | string;
|
|
66
|
+
borderRadius: number | string;
|
|
67
|
+
borderWidth: number | string;
|
|
68
|
+
color: Record<TagColor, string>;
|
|
69
|
+
};
|
|
70
|
+
|
|
60
71
|
// Тип для палітри
|
|
61
72
|
export type Theme = {
|
|
62
73
|
mode: 'light' | 'dark';
|
|
@@ -235,6 +246,7 @@ export type Theme = {
|
|
|
235
246
|
foreground: string;
|
|
236
247
|
background: string;
|
|
237
248
|
};
|
|
249
|
+
tag: Record<TagVariant, TagElementStyle>;
|
|
238
250
|
};
|
|
239
251
|
|
|
240
252
|
//TODO check and refactoring
|
package/src/Theme/utils.ts
CHANGED
|
@@ -173,3 +173,17 @@ export const getTypographyStyles = (theme: DefaultTheme, variant: string = 'body
|
|
|
173
173
|
export const getBreakpoint = (theme: DefaultTheme, size: Breakpoint = 'm') => {
|
|
174
174
|
return `@media (min-width: ${theme.breakpoints[size]}px)`;
|
|
175
175
|
};
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* Функція для отримання rgba кольору з hex формату
|
|
179
|
+
*/
|
|
180
|
+
export const hexToRgba = (hex: string, alpha: number): string => {
|
|
181
|
+
try {
|
|
182
|
+
const r = parseInt(hex.slice(1, 3), 16);
|
|
183
|
+
const g = parseInt(hex.slice(3, 5), 16);
|
|
184
|
+
const b = parseInt(hex.slice(5, 7), 16);
|
|
185
|
+
return `rgba(${r}, ${g}, ${b}, ${alpha})`;
|
|
186
|
+
} catch {
|
|
187
|
+
return hex;
|
|
188
|
+
}
|
|
189
|
+
};
|