@cyber-harbour/ui 1.0.59 → 1.0.61
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 +513 -43
- package/dist/index.d.ts +513 -43
- package/dist/index.js +343 -310
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +276 -243
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/Core/Alert/Alert.tsx +11 -5
- package/src/Core/Box/Box.tsx +19 -17
- package/src/Core/Button/Button.tsx +59 -55
- package/src/Core/Checkbox/Checkbox.tsx +6 -7
- package/src/Core/ContentLoader/ContentLoader.tsx +13 -0
- package/src/Core/ContentLoader/index.ts +1 -0
- package/src/Core/Drawer/Drawer.tsx +29 -14
- package/src/Core/Flex/FlexContainer.tsx +47 -45
- package/src/Core/Flex/FlexItem.tsx +19 -26
- package/src/Core/IconComponents/PencilIcon.tsx +16 -0
- package/src/Core/IconComponents/PointIcon.tsx +16 -0
- package/src/Core/IconComponents/index.ts +2 -0
- package/src/Core/Label/Label.tsx +31 -30
- package/src/Core/Line/Line.tsx +5 -5
- package/src/Core/LinerProgress/LinerProgress.tsx +14 -20
- package/src/Core/Switch/Switch.tsx +4 -4
- package/src/Core/Tag/Tag.tsx +29 -36
- package/src/Core/Tooltip/Tooltip.tsx +93 -0
- package/src/Core/Tooltip/index.ts +1 -0
- package/src/Core/Typography/Typography.tsx +31 -33
- package/src/Core/index.ts +2 -0
- package/src/Layouts/Container/Container.tsx +13 -7
- package/src/Theme/Breakpoint.tsx +50 -0
- package/src/Theme/ThemeProvider.tsx +5 -2
- package/src/Theme/{componentFabric.ts → componentFabric.tsx} +90 -36
- package/src/Theme/index.ts +1 -0
- package/src/Theme/themes/dark.ts +11 -0
- package/src/Theme/themes/light.ts +11 -0
- package/src/Theme/types.ts +11 -0
package/src/Core/Label/Label.tsx
CHANGED
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import styled from 'styled-components';
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
FabricComponent,
|
|
5
|
+
LabelSize,
|
|
6
|
+
createComponent,
|
|
7
|
+
createStyledComponent,
|
|
8
|
+
generatePropertySpaceStyle,
|
|
9
|
+
propToRem,
|
|
10
|
+
} from '../../Theme';
|
|
4
11
|
|
|
5
12
|
type LabelProps = FabricComponent<{
|
|
6
13
|
label?: any;
|
|
@@ -22,40 +29,34 @@ type LabelDirection = {
|
|
|
22
29
|
direction?: Omit<React.CSSProperties['flexDirection'], 'row' | 'row-reverse'>;
|
|
23
30
|
};
|
|
24
31
|
|
|
25
|
-
export const Label = (
|
|
26
|
-
label,
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
direction = 'column',
|
|
30
|
-
size = 'small',
|
|
31
|
-
errorText,
|
|
32
|
-
fullWidth,
|
|
33
|
-
...props
|
|
34
|
-
}: LabelProps) => {
|
|
35
|
-
const $isRow = direction === 'row' || direction === 'row-reverse';
|
|
36
|
-
const $width = $isRow ? (props as LabelDirectionRaw).childrenWidth || '50%' : '100%';
|
|
32
|
+
export const Label = createComponent<LabelProps>(
|
|
33
|
+
({ label, helpText, children, direction = 'column', size = 'small', errorText, fullWidth, ...props }) => {
|
|
34
|
+
const $isRow = direction === 'row' || direction === 'row-reverse';
|
|
35
|
+
const $width = $isRow ? (props as LabelDirectionRaw).childrenWidth || '50%' : '100%';
|
|
37
36
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
}
|
|
37
|
+
return (
|
|
38
|
+
<StyledLabel $size={size} $direction={direction} $fullWidth={fullWidth} $isRow={$isRow} {...props}>
|
|
39
|
+
{Boolean(label || helpText) && (
|
|
40
|
+
<LabelWrapper $width={$width}>
|
|
41
|
+
{!!label && <LabelText $size={size}>{label}</LabelText>}
|
|
42
|
+
{!!helpText && <HelpText $size={size}>{helpText}</HelpText>}
|
|
43
|
+
</LabelWrapper>
|
|
44
|
+
)}
|
|
45
|
+
<Wrapper $width={$width}>
|
|
46
|
+
{children}
|
|
47
|
+
{!!errorText && <ErrorText $size={size}>{errorText}</ErrorText>}
|
|
48
|
+
</Wrapper>
|
|
49
|
+
</StyledLabel>
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
);
|
|
53
53
|
|
|
54
54
|
type StyledProps = {
|
|
55
55
|
$size: LabelSize;
|
|
56
56
|
$direction?: LabelDirection['direction'] | LabelDirectionRaw['direction'];
|
|
57
57
|
$fullWidth?: boolean;
|
|
58
58
|
$isRow: boolean;
|
|
59
|
+
children?: any;
|
|
59
60
|
};
|
|
60
61
|
|
|
61
62
|
type WrapperProps = { $width: number | string };
|
|
@@ -107,8 +108,8 @@ const ErrorText = styled.div<TextProps>(
|
|
|
107
108
|
`
|
|
108
109
|
);
|
|
109
110
|
|
|
110
|
-
const StyledLabel =
|
|
111
|
-
styled.label
|
|
111
|
+
const StyledLabel = createStyledComponent<FabricComponent<StyledProps>>(
|
|
112
|
+
styled.label(
|
|
112
113
|
({
|
|
113
114
|
theme,
|
|
114
115
|
$direction = 'column',
|
package/src/Core/Line/Line.tsx
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createComponent, FabricComponent } from '../../Theme';
|
|
1
|
+
import { createComponent, createStyledComponent, FabricComponent, StyledFabricComponent } from '../../Theme';
|
|
2
2
|
import { styled } from 'styled-components';
|
|
3
3
|
|
|
4
4
|
type LineProps = FabricComponent<
|
|
@@ -7,16 +7,16 @@ type LineProps = FabricComponent<
|
|
|
7
7
|
} & Omit<React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, 'children'>
|
|
8
8
|
>;
|
|
9
9
|
|
|
10
|
-
export const Line = ({ direction = 'horizontal', ...props }
|
|
10
|
+
export const Line = createComponent<LineProps>(({ direction = 'horizontal', ...props }) => {
|
|
11
11
|
return <StyledLine {...props} $direction={direction} />;
|
|
12
|
-
};
|
|
12
|
+
});
|
|
13
13
|
|
|
14
14
|
interface StyledLineProps {
|
|
15
15
|
$direction: 'horizontal' | 'vertical';
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
const StyledLine =
|
|
19
|
-
styled.div
|
|
18
|
+
const StyledLine = createStyledComponent<StyledFabricComponent<StyledLineProps>>(
|
|
19
|
+
styled.div(
|
|
20
20
|
({ theme, $direction }) => `
|
|
21
21
|
width: ${$direction === 'horizontal' ? '100%' : theme.line.size};
|
|
22
22
|
height: ${$direction === 'vertical' ? '100%' : theme.line.size};
|
|
@@ -1,26 +1,20 @@
|
|
|
1
|
-
import { createComponent,
|
|
1
|
+
import { createComponent, createStyledComponent, propToRem, pxToRem, StyledFabricComponent } from '../../Theme';
|
|
2
2
|
import { styled } from 'styled-components';
|
|
3
3
|
|
|
4
4
|
type Direction = 'horizontal' | 'vertical';
|
|
5
5
|
|
|
6
|
-
type LinerProgressProps =
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
} & Omit<React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, 'children'>
|
|
13
|
-
>;
|
|
6
|
+
type LinerProgressProps = {
|
|
7
|
+
height?: number;
|
|
8
|
+
width?: string | number;
|
|
9
|
+
direction?: Direction;
|
|
10
|
+
value: number;
|
|
11
|
+
} & Omit<React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, 'children'>;
|
|
14
12
|
|
|
15
|
-
export const LinerProgress = (
|
|
16
|
-
height = 21,
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
...props
|
|
21
|
-
}: LinerProgressProps) => {
|
|
22
|
-
return <StyledLine {...props} $height={height} $value={value} $width={width} $direction={direction} />;
|
|
23
|
-
};
|
|
13
|
+
export const LinerProgress = createComponent<LinerProgressProps>(
|
|
14
|
+
({ height = 21, width = '100%', direction = 'horizontal', value, ...props }: LinerProgressProps) => {
|
|
15
|
+
return <StyledLine {...props} $height={height} $value={value} $width={width} $direction={direction} />;
|
|
16
|
+
}
|
|
17
|
+
);
|
|
24
18
|
|
|
25
19
|
interface StyledLineProps {
|
|
26
20
|
$height: number;
|
|
@@ -29,8 +23,8 @@ interface StyledLineProps {
|
|
|
29
23
|
$direction: Direction;
|
|
30
24
|
}
|
|
31
25
|
|
|
32
|
-
const StyledLine =
|
|
33
|
-
styled.div
|
|
26
|
+
const StyledLine = createStyledComponent<StyledFabricComponent<StyledLineProps>>(
|
|
27
|
+
styled.div(
|
|
34
28
|
({ theme, $height, $value, $width, $direction }) => `
|
|
35
29
|
width: ${propToRem($width, theme.baseSize)};
|
|
36
30
|
height: ${propToRem($height, theme.baseSize)};
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { InputHTMLAttributes } from 'react';
|
|
2
|
-
import { createComponent, destructSpaceProps, FabricComponent, pxToRem } from '../../Theme';
|
|
2
|
+
import { createComponent, createStyledComponent, destructSpaceProps, FabricComponent, pxToRem } from '../../Theme';
|
|
3
3
|
import { styled } from 'styled-components';
|
|
4
4
|
|
|
5
5
|
type SwitchProps = FabricComponent<Omit<InputHTMLAttributes<HTMLInputElement>, 'type'>>;
|
|
6
6
|
|
|
7
|
-
export const Switch = ({ className, ...props }
|
|
7
|
+
export const Switch = createComponent<SwitchProps>(({ className, ...props }) => {
|
|
8
8
|
const spaceProps = destructSpaceProps(props);
|
|
9
9
|
return (
|
|
10
10
|
<StyledLabel className={className} {...spaceProps}>
|
|
@@ -12,7 +12,7 @@ export const Switch = ({ className, ...props }: SwitchProps) => {
|
|
|
12
12
|
<StyledSwitch />
|
|
13
13
|
</StyledLabel>
|
|
14
14
|
);
|
|
15
|
-
};
|
|
15
|
+
});
|
|
16
16
|
|
|
17
17
|
const StyledSwitch = styled.span(
|
|
18
18
|
({ theme }) => `
|
|
@@ -63,7 +63,7 @@ const HiddenInput = styled.input(
|
|
|
63
63
|
`
|
|
64
64
|
);
|
|
65
65
|
|
|
66
|
-
const StyledLabel =
|
|
66
|
+
const StyledLabel = createStyledComponent(
|
|
67
67
|
styled.label`
|
|
68
68
|
position: relative;
|
|
69
69
|
display: inline-block;
|
package/src/Core/Tag/Tag.tsx
CHANGED
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
TagColor,
|
|
8
8
|
hexToRgba,
|
|
9
9
|
generatePropertySpaceStyle,
|
|
10
|
+
createStyledComponent,
|
|
10
11
|
} from '../../Theme';
|
|
11
12
|
import { CrossIcon } from '../IconComponents';
|
|
12
13
|
|
|
@@ -22,41 +23,33 @@ type TagProps = FabricComponent<{
|
|
|
22
23
|
}> &
|
|
23
24
|
Omit<React.HTMLAttributes<HTMLDivElement>, 'children'>;
|
|
24
25
|
|
|
25
|
-
export const Tag = (
|
|
26
|
-
children,
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
}}
|
|
53
|
-
>
|
|
54
|
-
<CrossIcon />
|
|
55
|
-
</DeleteButton>
|
|
56
|
-
)}
|
|
57
|
-
</StyledContainer>
|
|
58
|
-
);
|
|
59
|
-
};
|
|
26
|
+
export const Tag = createComponent<TagProps>(
|
|
27
|
+
({ children, variant = 'fill', color = 'default', className, disabled, icon, onClick, onDelete, ...props }) => {
|
|
28
|
+
return (
|
|
29
|
+
<StyledContainer
|
|
30
|
+
$variant={variant}
|
|
31
|
+
$color={color}
|
|
32
|
+
$clickable={!!onClick && !disabled}
|
|
33
|
+
onClick={!disabled ? onClick : undefined}
|
|
34
|
+
className={className}
|
|
35
|
+
{...props}
|
|
36
|
+
>
|
|
37
|
+
{!!children && <Content>{children}</Content>}
|
|
38
|
+
{!!onDelete && !disabled && (
|
|
39
|
+
<DeleteButton
|
|
40
|
+
aria-label="delete"
|
|
41
|
+
onClick={(e) => {
|
|
42
|
+
e.stopPropagation();
|
|
43
|
+
onDelete();
|
|
44
|
+
}}
|
|
45
|
+
>
|
|
46
|
+
<CrossIcon />
|
|
47
|
+
</DeleteButton>
|
|
48
|
+
)}
|
|
49
|
+
</StyledContainer>
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
);
|
|
60
53
|
|
|
61
54
|
type StyledProps = {
|
|
62
55
|
$variant: TagVariant;
|
|
@@ -138,6 +131,6 @@ const Container = styled.div<FabricComponent<StyledProps>>(
|
|
|
138
131
|
}
|
|
139
132
|
);
|
|
140
133
|
|
|
141
|
-
const StyledContainer =
|
|
134
|
+
const StyledContainer = createStyledComponent(Container, {
|
|
142
135
|
ignoreStyles: ['padding-block', 'padding-inline'],
|
|
143
136
|
});
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { useCallback, useState } from 'react';
|
|
2
|
+
import { Popover, PopoverAlign, PopoverPosition } from 'react-tiny-popover';
|
|
3
|
+
import { createComponent, pxToRem } from '../../Theme';
|
|
4
|
+
import { styled } from 'styled-components';
|
|
5
|
+
|
|
6
|
+
interface TooltipProps {
|
|
7
|
+
className?: string;
|
|
8
|
+
children?: any;
|
|
9
|
+
content?: any;
|
|
10
|
+
positions?: PopoverPosition[] | PopoverPosition;
|
|
11
|
+
align?: PopoverAlign;
|
|
12
|
+
anchorClassName?: string;
|
|
13
|
+
offset?: number;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export const Tooltip = createComponent<TooltipProps>(
|
|
17
|
+
({ className, positions = ['top'], align = 'center', anchorClassName, content, offset = 6, children }) => {
|
|
18
|
+
const [isOpen, setIsOpen] = useState<boolean>(false);
|
|
19
|
+
|
|
20
|
+
const position = Array.isArray(positions) ? positions[0] : positions;
|
|
21
|
+
|
|
22
|
+
const handleMouseEnter = useCallback(() => {
|
|
23
|
+
if (content) setIsOpen(true);
|
|
24
|
+
}, [content]);
|
|
25
|
+
|
|
26
|
+
const handleMouseLeave = useCallback(() => {
|
|
27
|
+
setIsOpen(false);
|
|
28
|
+
}, []);
|
|
29
|
+
|
|
30
|
+
return (
|
|
31
|
+
<Popover
|
|
32
|
+
padding={offset}
|
|
33
|
+
positions={positions}
|
|
34
|
+
isOpen={isOpen}
|
|
35
|
+
align={align}
|
|
36
|
+
content={
|
|
37
|
+
!!content && (
|
|
38
|
+
<StyledContent className={className} $position={position} $offset={offset}>
|
|
39
|
+
{content}
|
|
40
|
+
</StyledContent>
|
|
41
|
+
)
|
|
42
|
+
}
|
|
43
|
+
containerStyle={{
|
|
44
|
+
zIndex: `${9999}`,
|
|
45
|
+
}}
|
|
46
|
+
>
|
|
47
|
+
<StyledAnchor onMouseEnter={handleMouseEnter} onMouseLeave={handleMouseLeave} className={anchorClassName}>
|
|
48
|
+
{children}
|
|
49
|
+
</StyledAnchor>
|
|
50
|
+
</Popover>
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
);
|
|
54
|
+
const StyledAnchor = styled.div`
|
|
55
|
+
display: inline-block;
|
|
56
|
+
`;
|
|
57
|
+
|
|
58
|
+
const StyledContent = styled.div<{ $position: PopoverPosition; $offset: number }>(
|
|
59
|
+
({ theme, $position, $offset }) => `
|
|
60
|
+
padding: ${theme.tooltip.padding};
|
|
61
|
+
max-width: ${theme.tooltip.maxWidth};
|
|
62
|
+
border-radius: ${theme.tooltip.borderRadius};
|
|
63
|
+
background: ${theme.tooltip.background};
|
|
64
|
+
box-shadow: ${theme.tooltip.shadow};
|
|
65
|
+
|
|
66
|
+
color: ${theme.tooltip.color};
|
|
67
|
+
font-size: ${theme.tooltip.fontSize};
|
|
68
|
+
line-height: 1.4;
|
|
69
|
+
word-break: break-word;
|
|
70
|
+
white-space: pre-line;
|
|
71
|
+
animation: fadeIn-${$position} 0.3s ease forwards;
|
|
72
|
+
transform-origin: ${
|
|
73
|
+
$position === 'top' ? 'bottom' : $position === 'bottom' ? 'top' : $position === 'left' ? 'right' : 'left'
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
@keyframes fadeIn-top {
|
|
77
|
+
from { opacity: 0.5; transform: translateY(${pxToRem($offset, theme.baseSize)}); }
|
|
78
|
+
to { opacity: 1; transform: translateY(0); }
|
|
79
|
+
}
|
|
80
|
+
@keyframes fadeIn-bottom {
|
|
81
|
+
from { opacity: 0.5; transform: translateY(-${pxToRem($offset, theme.baseSize)}); }
|
|
82
|
+
to { opacity: 1; transform: translateY(0); }
|
|
83
|
+
}
|
|
84
|
+
@keyframes fadeIn-left {
|
|
85
|
+
from { opacity: 0.5; transform: translateX(${pxToRem($offset, theme.baseSize)}); }
|
|
86
|
+
to { opacity: 1; transform: translateX(0); }
|
|
87
|
+
}
|
|
88
|
+
@keyframes fadeIn-right {
|
|
89
|
+
from { opacity: 0.5; transform: translateX(-${pxToRem($offset, theme.baseSize)}); }
|
|
90
|
+
to { opacity: 1; transform: translateX(0); }
|
|
91
|
+
}
|
|
92
|
+
`
|
|
93
|
+
);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './Tooltip';
|
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
import styled from 'styled-components';
|
|
2
2
|
import { CSSProperties, ElementType } from 'react';
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
ColorVariant,
|
|
5
|
+
createComponent,
|
|
6
|
+
createStyledComponent,
|
|
7
|
+
FabricComponent,
|
|
8
|
+
StyledFabricComponent,
|
|
9
|
+
TypographyVariant,
|
|
10
|
+
} from '../../Theme';
|
|
4
11
|
import { resolveThemeColor } from '../../Theme/utils';
|
|
5
12
|
|
|
6
13
|
type TypographyProps = FabricComponent<{
|
|
@@ -25,8 +32,8 @@ type StyledProps = {
|
|
|
25
32
|
};
|
|
26
33
|
|
|
27
34
|
// Create a styled component that can be dynamically rendered as different HTML elements
|
|
28
|
-
const StyledTypography =
|
|
29
|
-
styled('div')
|
|
35
|
+
const StyledTypography = createStyledComponent<StyledFabricComponent<StyledProps>>(
|
|
36
|
+
styled('div')(({ theme, $variant, $color, $weight = '400', $style = 'initial', $ellipsis }) => {
|
|
30
37
|
// Resolve color from theme if it's a theme color path, or use the direct color value
|
|
31
38
|
|
|
32
39
|
return `
|
|
@@ -39,34 +46,25 @@ const StyledTypography = createComponent(
|
|
|
39
46
|
})
|
|
40
47
|
);
|
|
41
48
|
|
|
42
|
-
export const Typography = (
|
|
43
|
-
variant = 'body',
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
weight,
|
|
47
|
-
fontStyle,
|
|
48
|
-
color,
|
|
49
|
-
className,
|
|
50
|
-
style,
|
|
51
|
-
ellipsis = false,
|
|
52
|
-
...props
|
|
53
|
-
}: TypographyProps) => {
|
|
54
|
-
// Determine which HTML element to render based on the variant if not explicitly specified
|
|
55
|
-
const Element = element || (variant.startsWith('h') ? variant : 'p');
|
|
49
|
+
export const Typography = createComponent<TypographyProps>(
|
|
50
|
+
({ variant = 'body', element, children, weight, fontStyle, color, className, style, ellipsis = false, ...props }) => {
|
|
51
|
+
// Determine which HTML element to render based on the variant if not explicitly specified
|
|
52
|
+
const Element = element || (variant.startsWith('h') ? variant : 'p');
|
|
56
53
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
}
|
|
54
|
+
return (
|
|
55
|
+
<StyledTypography
|
|
56
|
+
as={Element}
|
|
57
|
+
$variant={variant}
|
|
58
|
+
$weight={weight}
|
|
59
|
+
$style={fontStyle}
|
|
60
|
+
$color={color}
|
|
61
|
+
$ellipsis={ellipsis}
|
|
62
|
+
className={className}
|
|
63
|
+
style={style}
|
|
64
|
+
{...props}
|
|
65
|
+
>
|
|
66
|
+
{children}
|
|
67
|
+
</StyledTypography>
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
);
|
package/src/Core/index.ts
CHANGED
|
@@ -1,21 +1,27 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
createComponent,
|
|
3
|
+
createStyledComponent,
|
|
4
|
+
FabricComponent,
|
|
5
|
+
generatePropertySpaceStyle,
|
|
6
|
+
pxToRem,
|
|
7
|
+
} from '../../Theme';
|
|
2
8
|
import { styled } from 'styled-components';
|
|
3
9
|
|
|
4
|
-
type ContainerProps =
|
|
10
|
+
type ContainerProps = {
|
|
5
11
|
children: any;
|
|
6
12
|
maxWidth?: string | number;
|
|
7
|
-
}
|
|
13
|
+
};
|
|
8
14
|
|
|
9
15
|
type StyledContainerProps = {
|
|
10
16
|
$maxWidth?: string | number;
|
|
11
17
|
};
|
|
12
18
|
|
|
13
|
-
export const Container = ({ maxWidth, ...props }
|
|
19
|
+
export const Container = createComponent<ContainerProps>(({ maxWidth, ...props }) => {
|
|
14
20
|
return <StyledContainer {...props} $maxWidth={maxWidth} />;
|
|
15
|
-
};
|
|
21
|
+
});
|
|
16
22
|
|
|
17
|
-
const StyledContainer =
|
|
18
|
-
styled.div
|
|
23
|
+
const StyledContainer = createStyledComponent<FabricComponent<StyledContainerProps>>(
|
|
24
|
+
styled.div(({ theme, $maxWidth, px = 20 }) => {
|
|
19
25
|
return `
|
|
20
26
|
${generatePropertySpaceStyle(theme, 'padding-inline', px)}
|
|
21
27
|
width: 100%;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { createContext, useContext, useEffect, useLayoutEffect, useMemo, useState } from 'react';
|
|
2
|
+
import { Theme } from './types';
|
|
3
|
+
import { useTheme } from 'styled-components';
|
|
4
|
+
import { breakpoints } from './themes/config';
|
|
5
|
+
|
|
6
|
+
type Breakpoint = keyof Theme['breakpoints'];
|
|
7
|
+
|
|
8
|
+
const getBreakpoint = (breakpoints: Theme['breakpoints']): Breakpoint => {
|
|
9
|
+
if (window !== undefined) {
|
|
10
|
+
const width = window.innerWidth;
|
|
11
|
+
for (const [key, value] of Object.entries(breakpoints)) {
|
|
12
|
+
if (width < value) {
|
|
13
|
+
return key as Breakpoint;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
const keys = Object.keys(breakpoints) as Breakpoint[];
|
|
18
|
+
|
|
19
|
+
return keys[keys.length - 1];
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
const BreakpointContext = createContext<Breakpoint>(getBreakpoint(breakpoints));
|
|
23
|
+
|
|
24
|
+
export const BreakpointProvider = ({ children }: { children: any }) => {
|
|
25
|
+
const theme = useTheme();
|
|
26
|
+
const [breakpoint, setBreakpoint] = useState<Breakpoint>(getBreakpoint(theme.breakpoints));
|
|
27
|
+
|
|
28
|
+
useEffect(() => {
|
|
29
|
+
const handleResize = () => {
|
|
30
|
+
const newBreakpoint = getBreakpoint(theme.breakpoints);
|
|
31
|
+
if (newBreakpoint !== breakpoint) {
|
|
32
|
+
setBreakpoint(newBreakpoint);
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
window.addEventListener('resize', handleResize);
|
|
37
|
+
return () => {
|
|
38
|
+
window.removeEventListener('resize', handleResize);
|
|
39
|
+
};
|
|
40
|
+
}, [breakpoint]);
|
|
41
|
+
|
|
42
|
+
return <BreakpointContext.Provider value={breakpoint}>{children}</BreakpointContext.Provider>;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
export const useBreakpoint = () => {
|
|
46
|
+
const currentBreakpoint = useContext(BreakpointContext);
|
|
47
|
+
const theme = useTheme();
|
|
48
|
+
const breakpointsOrder = useMemo(() => Object.keys(theme.breakpoints) as Breakpoint[], [theme.breakpoints]);
|
|
49
|
+
return { currentBreakpoint, breakpointsOrder: breakpointsOrder };
|
|
50
|
+
};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { StyleSheetManager, ThemeProvider as ThemeProviderStyled, WebTarget } from 'styled-components';
|
|
2
2
|
import { lightTheme, darkTheme } from './themes';
|
|
3
3
|
import { GlobalStyle } from './GlobalStyle';
|
|
4
|
+
import { BreakpointProvider } from './Breakpoint';
|
|
4
5
|
|
|
5
6
|
interface ThemeProviderProps {
|
|
6
7
|
children: any;
|
|
@@ -12,8 +13,10 @@ export const ThemeProvider = ({ children, mode }: ThemeProviderProps) => {
|
|
|
12
13
|
return (
|
|
13
14
|
<StyleSheetManager shouldForwardProp={shouldForwardProp}>
|
|
14
15
|
<ThemeProviderStyled theme={mode == 'light' || mode === 'LIGHT' ? lightTheme : darkTheme}>
|
|
15
|
-
<
|
|
16
|
-
|
|
16
|
+
<BreakpointProvider>
|
|
17
|
+
<GlobalStyle />
|
|
18
|
+
{children}
|
|
19
|
+
</BreakpointProvider>
|
|
17
20
|
</ThemeProviderStyled>
|
|
18
21
|
</StyleSheetManager>
|
|
19
22
|
);
|