@cyber-harbour/ui 1.0.51 → 1.0.52

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cyber-harbour/ui",
3
- "version": "1.0.51",
3
+ "version": "1.0.52",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/index.mjs",
6
6
  "types": "dist/index.d.ts",
@@ -0,0 +1,74 @@
1
+ import React from 'react';
2
+ import styled from 'styled-components';
3
+ import { FabricComponent, createComponent, destructSpaceProps, pxToRem } from '../../Theme';
4
+
5
+ type CheckboxProps = FabricComponent<{
6
+ label?: any;
7
+ }> &
8
+ Omit<React.InputHTMLAttributes<HTMLInputElement>, 'type'>;
9
+
10
+ export const Checkbox = ({ label, className, disabled, ...props }: CheckboxProps) => {
11
+ const spaceProps = destructSpaceProps(props);
12
+ return (
13
+ <StyledCheckbox className={className} $disabled={disabled} {...spaceProps}>
14
+ <HiddenInput type="checkbox" disabled={disabled} {...props} />
15
+ <CustomCheckbox />
16
+ {!!label && <LabelText>{label}</LabelText>}
17
+ </StyledCheckbox>
18
+ );
19
+ };
20
+
21
+ const CustomCheckbox = styled.div(
22
+ ({ theme }) => `
23
+ width: ${pxToRem(15)};
24
+ height: ${pxToRem(15)};
25
+ border-radius: ${pxToRem(2)};
26
+ border: 1px solid ${theme.colors.stroke.main};
27
+ background-color: ${theme.colors.background};
28
+ transition: all 0.2s ease;
29
+ `
30
+ );
31
+
32
+ const LabelText = styled.span(
33
+ ({ theme }) => `
34
+ margin-left: ${pxToRem(5)};
35
+ font-size: ${theme.typography.variants.h3.fontSize};
36
+ color: ${theme.colors.text.main};
37
+ `
38
+ );
39
+
40
+ const HiddenInput = styled.input`
41
+ border: 0;
42
+ clip: rect(0 0 0 0);
43
+ height: 1px;
44
+ width: 1px;
45
+ margin: -1px;
46
+ overflow: hidden;
47
+ padding: 0;
48
+ position: absolute;
49
+ `;
50
+
51
+ const StyledCheckbox = createComponent(
52
+ styled.label<{ $disabled?: boolean }>(({ theme, $disabled }) => {
53
+ return `
54
+ position: relative;
55
+ display: flex;
56
+ align-items: center;
57
+ cursor: ${$disabled ? 'not-allowed' : 'pointer'};
58
+
59
+ &:hover {
60
+ ${HiddenInput}:not(:disabled) + ${CustomCheckbox} {
61
+ border-color: ${theme.colors.primary.main};
62
+ }
63
+ }
64
+
65
+ ${HiddenInput}:checked + ${CustomCheckbox} {
66
+ background-color: ${theme.colors.primary.main};
67
+ border-color: ${theme.colors.primary.main};
68
+ }
69
+ ${HiddenInput}:disabled + ${CustomCheckbox} {
70
+ background-color: ${theme.colors.disable};
71
+ }
72
+ `;
73
+ })
74
+ );
@@ -0,0 +1 @@
1
+ export * from './Checkbox';
@@ -0,0 +1,122 @@
1
+ import React from 'react';
2
+ import styled from 'styled-components';
3
+ import { FabricComponent, LabelSize, createComponent, generatePropertySpaceStyle, propToRem } from '../../Theme';
4
+
5
+ type LabelProps = FabricComponent<{
6
+ label?: any;
7
+ helpText?: any;
8
+ errorText?: string;
9
+ size?: LabelSize;
10
+ children: any;
11
+ }> &
12
+ Omit<React.LabelHTMLAttributes<HTMLLabelElement>, 'children'> &
13
+ (LabelDirection | LabelDirectionRaw);
14
+
15
+ type LabelDirectionRaw = {
16
+ direction?: 'row' | 'row-reverse';
17
+ childrenWidth?: number | string;
18
+ };
19
+
20
+ type LabelDirection = {
21
+ direction?: Omit<React.CSSProperties['flexDirection'], 'row' | 'row-reverse'>;
22
+ };
23
+
24
+ export const Label = ({
25
+ label,
26
+ helpText,
27
+ children,
28
+ direction = 'column',
29
+ size = 'small',
30
+ errorText,
31
+ ...props
32
+ }: LabelProps) => {
33
+ const $width =
34
+ direction === 'row' || direction === 'row-reverse' ? (props as LabelDirectionRaw).childrenWidth || '50%' : '100%';
35
+
36
+ return (
37
+ <StyledLabel $size={size} $direction={direction} {...props}>
38
+ <LabelWrapper $width={$width} $size={size}>
39
+ {!!label && <LabelText $size={size}>{label}</LabelText>}
40
+ {!!helpText && <HelpText $size={size}>{helpText}</HelpText>}
41
+ </LabelWrapper>
42
+ <Wrapper $size={size} $width={$width}>
43
+ {children}
44
+ {!!errorText && <ErrorText $size={size}>{errorText}</ErrorText>}
45
+ </Wrapper>
46
+ </StyledLabel>
47
+ );
48
+ };
49
+
50
+ type StyledProps = {
51
+ $size: LabelSize;
52
+ $direction?: LabelDirection['direction'] | LabelDirectionRaw['direction'];
53
+ };
54
+
55
+ const Wrapper = styled.div<StyledProps & { $width: number | string }>(
56
+ ({ theme, $width }) => `
57
+ flex-basis: 100%;
58
+ @media (min-width: ${theme.breakpoints.m}px) {
59
+ flex-basis: ${propToRem($width, theme.baseSize)};
60
+ }
61
+ `
62
+ );
63
+
64
+ const LabelWrapper = styled(Wrapper)<StyledProps>`
65
+ align-self: flex-start;
66
+ `;
67
+
68
+ const LabelText = styled.div<StyledProps>(
69
+ ({ theme, $size }) => `
70
+ line-height: 1.2;
71
+ font-weight: 500;
72
+ font-size: ${theme.label.sizes[$size].fontSize};
73
+ color: ${theme.label.color};
74
+ cursor: pointer;
75
+ :hover {
76
+ color: ${theme.colors.primary.main};
77
+ }
78
+
79
+ `
80
+ );
81
+
82
+ const HelpText = styled.div<StyledProps>(
83
+ ({ theme, $size }) => `
84
+ margin-top: ${theme.label.sizes[$size].helpText.marginTop};
85
+ word-break: break-word;
86
+ line-height: 1.2;
87
+ font-size: ${theme.label.sizes[$size].helpText.fontSize};
88
+ color: ${theme.label.helpTextColor};
89
+ `
90
+ );
91
+ const ErrorText = styled.div<StyledProps>(
92
+ ({ theme, $size }) => `
93
+ margin-top: ${theme.label.sizes[$size].helpText.marginTop};
94
+ word-break: break-word;
95
+ line-height: 1.2;
96
+ font-size: ${theme.label.sizes[$size].helpText.fontSize};
97
+ color: ${theme.colors.error};
98
+ `
99
+ );
100
+
101
+ const StyledLabel = createComponent(
102
+ styled.label<FabricComponent<StyledProps>>(
103
+ ({ theme, $direction = 'column', $size, mb = theme.label.sizes[$size].marginBottom }) => {
104
+ return `
105
+ display: flex;
106
+ align-items: center;
107
+ justify-content: space-between;
108
+ width: 100%;
109
+ min-width: 0;
110
+ flex-direction: column;
111
+
112
+ @media (min-width: ${theme.breakpoints.m}px) {
113
+ flex-direction: ${$direction};
114
+ }
115
+
116
+ gap: ${theme.label.sizes[$size].gap};
117
+ ${generatePropertySpaceStyle(theme, 'margin-bottom', mb)};
118
+ `;
119
+ }
120
+ ),
121
+ { ignoreStyles: ['margin-bottom'] }
122
+ );
@@ -0,0 +1 @@
1
+ export * from './Label';
package/src/Core/index.ts CHANGED
@@ -16,3 +16,5 @@ export * from './Line';
16
16
  export * from './EmptyData';
17
17
  export * from './Tag';
18
18
  export * from './Alert';
19
+ export * from './Label';
20
+ export * from './Checkbox';
@@ -1,7 +1,7 @@
1
1
  import styled, { css, IStyledComponent, DefaultTheme, WebTarget } from 'styled-components';
2
2
  import { pxToRem } from './utils';
3
3
 
4
- type MarginProps = {
4
+ type SpaceProps = {
5
5
  m?: string | number; // margin
6
6
  mt?: string | number; // margin-top
7
7
  mr?: string | number; // margin-right
@@ -18,7 +18,7 @@ type MarginProps = {
18
18
  py?: string | number; // padding-top + padding-bottom
19
19
  };
20
20
 
21
- export type FabricComponent<T = object> = T & MarginProps;
21
+ export type FabricComponent<T = object> = T & SpaceProps;
22
22
 
23
23
  const marginStyles = ({ ignoreStyles }: FabricComponentOptions = {}) =>
24
24
  css<FabricComponent>(({ theme, ...props }) => {
@@ -91,3 +91,15 @@ export const createComponent = <T extends object = {}>(
91
91
  ${paddingStyles(options)}
92
92
  `;
93
93
  };
94
+
95
+ export const destructSpaceProps = <T extends FabricComponent>(props: T): SpaceProps => {
96
+ const rest: SpaceProps = {};
97
+ ['m', 'mt', 'mr', 'mb', 'ml', 'mx', 'my', 'p', 'pt', 'pr', 'pb', 'pl', 'px', 'py'].forEach((key) => {
98
+ if (key in props) {
99
+ rest[key as keyof SpaceProps] = props[key as keyof SpaceProps];
100
+ delete props[key as keyof SpaceProps];
101
+ }
102
+ });
103
+
104
+ return rest;
105
+ };
@@ -758,6 +758,24 @@ export const darkThemePx: Theme = {
758
758
  background: '#FFFBE0',
759
759
  },
760
760
  },
761
+ label: {
762
+ sizes: {
763
+ small: {
764
+ fontSize: 14,
765
+ gap: 10,
766
+ marginBottom: 20,
767
+ helpText: { fontSize: 12, marginTop: 5 },
768
+ },
769
+ medium: {
770
+ fontSize: 16,
771
+ gap: 10,
772
+ marginBottom: 25,
773
+ helpText: { fontSize: 14, marginTop: 5 },
774
+ },
775
+ },
776
+ color: '#ffffff',
777
+ helpTextColor: '#535353',
778
+ },
761
779
  };
762
780
 
763
781
  export const darkTheme = convertPaletteToRem(darkThemePx, darkThemePx.baseSize) as DefaultTheme;
@@ -757,6 +757,24 @@ export const lightThemePx: Theme = {
757
757
  background: '#FFFBE0',
758
758
  },
759
759
  },
760
+ label: {
761
+ sizes: {
762
+ small: {
763
+ fontSize: 14,
764
+ gap: 10,
765
+ marginBottom: 20,
766
+ helpText: { fontSize: 12, marginTop: 5 },
767
+ },
768
+ medium: {
769
+ fontSize: 16,
770
+ gap: 10,
771
+ marginBottom: 25,
772
+ helpText: { fontSize: 14, marginTop: 5 },
773
+ },
774
+ },
775
+ color: '#101010',
776
+ helpTextColor: '#99989C',
777
+ },
760
778
  };
761
779
 
762
780
  export const lightTheme = convertPaletteToRem(lightThemePx, lightThemePx.baseSize) as DefaultTheme;
@@ -22,6 +22,14 @@ export type TagColor =
22
22
  | 'orange'
23
23
  | string;
24
24
 
25
+ export type LabelSize = 'small' | 'medium';
26
+ export type LabelSizeStyle = {
27
+ fontSize: number | string;
28
+ gap: number | string;
29
+ marginBottom: number | string;
30
+ helpText: { fontSize: number | string; marginTop: number | string };
31
+ };
32
+
25
33
  // Типи для spacing та breakpoints
26
34
  export type Breakpoint = 'xs' | 's' | 'm' | 'l' | 'xl';
27
35
 
@@ -274,6 +282,11 @@ export type Theme = {
274
282
  background: string;
275
283
  };
276
284
  };
285
+ label: {
286
+ sizes: Record<LabelSize, LabelSizeStyle>;
287
+ color: string;
288
+ helpTextColor: string;
289
+ };
277
290
  };
278
291
 
279
292
  //TODO check and refactoring
@@ -88,6 +88,27 @@ const IGNORE_CONVERT_KEYS: Record<string, string[] | boolean> = {
88
88
  baseSize: true,
89
89
  };
90
90
 
91
+ /**
92
+ * Converts a prop value to rem units if needed
93
+ *
94
+ * @param value - The pixel value to convert. Can be a number or a string with 'px' suffix
95
+ * @param baseSize - Base font size in pixels. Default is 16px (browser default)
96
+ * @returns The value in rem units as a string (e.g., "1.25rem")
97
+ */
98
+ export const propToRem = (value: number | string, baseSize: number = 16): string => {
99
+ if (typeof value === 'string' && value.trim().endsWith('%')) return value; // Return percentage values as-is
100
+ const numericValue = typeof value === 'string' ? parseFloat(value) : value;
101
+
102
+ // Handle invalid values
103
+ if (isNaN(numericValue)) {
104
+ return `${value}`;
105
+ }
106
+
107
+ // Convert to rem and round to 4 decimal places for precision
108
+ const remValue = (numericValue / baseSize).toFixed(4).replace(/\.?0+$/, '');
109
+
110
+ return `${remValue}rem`;
111
+ };
91
112
  /**
92
113
  * Recursively converts all pixel values in an object to rem units
93
114
  *