@cyber-harbour/ui 1.0.60 → 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 +482 -44
- package/dist/index.d.ts +482 -44
- package/dist/index.js +219 -219
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +234 -234
- 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/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 +35 -41
- package/src/Core/Typography/Typography.tsx +31 -33
- package/src/Core/index.ts +1 -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
|
@@ -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
|
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useCallback, useState } from 'react';
|
|
2
2
|
import { Popover, PopoverAlign, PopoverPosition } from 'react-tiny-popover';
|
|
3
|
-
import { pxToRem } from '../../Theme';
|
|
3
|
+
import { createComponent, pxToRem } from '../../Theme';
|
|
4
4
|
import { styled } from 'styled-components';
|
|
5
5
|
|
|
6
6
|
interface TooltipProps {
|
|
@@ -13,50 +13,44 @@ interface TooltipProps {
|
|
|
13
13
|
offset?: number;
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
export const Tooltip = (
|
|
17
|
-
className,
|
|
18
|
-
|
|
19
|
-
align = 'center',
|
|
20
|
-
anchorClassName,
|
|
21
|
-
content,
|
|
22
|
-
offset = 6,
|
|
23
|
-
children,
|
|
24
|
-
}: TooltipProps) => {
|
|
25
|
-
const [isOpen, setIsOpen] = useState<boolean>(false);
|
|
16
|
+
export const Tooltip = createComponent<TooltipProps>(
|
|
17
|
+
({ className, positions = ['top'], align = 'center', anchorClassName, content, offset = 6, children }) => {
|
|
18
|
+
const [isOpen, setIsOpen] = useState<boolean>(false);
|
|
26
19
|
|
|
27
|
-
|
|
20
|
+
const position = Array.isArray(positions) ? positions[0] : positions;
|
|
28
21
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
22
|
+
const handleMouseEnter = useCallback(() => {
|
|
23
|
+
if (content) setIsOpen(true);
|
|
24
|
+
}, [content]);
|
|
32
25
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
26
|
+
const handleMouseLeave = useCallback(() => {
|
|
27
|
+
setIsOpen(false);
|
|
28
|
+
}, []);
|
|
36
29
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
}
|
|
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
|
+
);
|
|
60
54
|
const StyledAnchor = styled.div`
|
|
61
55
|
display: inline-block;
|
|
62
56
|
`;
|
|
@@ -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
|
);
|
|
@@ -1,5 +1,9 @@
|
|
|
1
|
-
import styled, { css,
|
|
1
|
+
import styled, { css, DefaultTheme } from 'styled-components';
|
|
2
2
|
import { pxToRem } from './utils';
|
|
3
|
+
import React, { useMemo } from 'react';
|
|
4
|
+
import { useBreakpoint } from './Breakpoint';
|
|
5
|
+
import { Breakpoint } from './types';
|
|
6
|
+
import { breakpoints } from './themes/config';
|
|
3
7
|
|
|
4
8
|
type SpaceProps = {
|
|
5
9
|
m?: string | number; // margin
|
|
@@ -18,9 +22,39 @@ type SpaceProps = {
|
|
|
18
22
|
py?: string | number; // padding-top + padding-bottom
|
|
19
23
|
};
|
|
20
24
|
|
|
21
|
-
|
|
25
|
+
type GeneratedFabricMarginProperties =
|
|
26
|
+
| 'margin'
|
|
27
|
+
| 'margin-top'
|
|
28
|
+
| 'margin-right'
|
|
29
|
+
| 'margin-bottom'
|
|
30
|
+
| 'margin-left'
|
|
31
|
+
| 'margin-inline'
|
|
32
|
+
| 'margin-block'
|
|
33
|
+
| 'padding'
|
|
34
|
+
| 'padding-top'
|
|
35
|
+
| 'padding-right'
|
|
36
|
+
| 'padding-bottom'
|
|
37
|
+
| 'padding-left'
|
|
38
|
+
| 'padding-inline'
|
|
39
|
+
| 'padding-block';
|
|
40
|
+
|
|
41
|
+
type MediaProps<T = object> = {
|
|
42
|
+
media?: {
|
|
43
|
+
[key in Breakpoint]?: Partial<T>;
|
|
44
|
+
};
|
|
45
|
+
};
|
|
22
46
|
|
|
23
|
-
|
|
47
|
+
type FabricStyledComponentOptions = {
|
|
48
|
+
ignoreStyles?: GeneratedFabricMarginProperties[] | undefined; // Ignore margin styles
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
type CreatedFabricComponent<T extends FabricComponent> =
|
|
52
|
+
| React.ComponentType<Omit<T, 'media'>>
|
|
53
|
+
| React.ForwardRefExoticComponent<Omit<T, 'media'>>;
|
|
54
|
+
export type FabricComponent<T = object> = T & SpaceProps & MediaProps<T>;
|
|
55
|
+
export type StyledFabricComponent<T = object> = T & SpaceProps;
|
|
56
|
+
|
|
57
|
+
const marginStyles = ({ ignoreStyles }: FabricStyledComponentOptions = {}) =>
|
|
24
58
|
css<FabricComponent>(({ theme, ...props }) => {
|
|
25
59
|
return `
|
|
26
60
|
${generatePropertySpaceStyle(theme, 'margin', props.m, ignoreStyles)}
|
|
@@ -33,7 +67,7 @@ const marginStyles = ({ ignoreStyles }: FabricComponentOptions = {}) =>
|
|
|
33
67
|
`;
|
|
34
68
|
});
|
|
35
69
|
|
|
36
|
-
const paddingStyles = ({ ignoreStyles }:
|
|
70
|
+
const paddingStyles = ({ ignoreStyles }: FabricStyledComponentOptions = {}) =>
|
|
37
71
|
css<FabricComponent>(({ theme, ...props }) => {
|
|
38
72
|
return `
|
|
39
73
|
${generatePropertySpaceStyle(theme, 'padding', props.p, ignoreStyles)}
|
|
@@ -46,21 +80,17 @@ const paddingStyles = ({ ignoreStyles }: FabricComponentOptions = {}) =>
|
|
|
46
80
|
`;
|
|
47
81
|
});
|
|
48
82
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
| 'padding-bottom'
|
|
61
|
-
| 'padding-left'
|
|
62
|
-
| 'padding-inline'
|
|
63
|
-
| 'padding-block';
|
|
83
|
+
export const destructSpaceProps = <T extends FabricComponent>(props: T): SpaceProps => {
|
|
84
|
+
const rest: SpaceProps = {};
|
|
85
|
+
['m', 'mt', 'mr', 'mb', 'ml', 'mx', 'my', 'p', 'pt', 'pr', 'pb', 'pl', 'px', 'py'].forEach((key) => {
|
|
86
|
+
if (key in props) {
|
|
87
|
+
rest[key as keyof SpaceProps] = props[key as keyof SpaceProps];
|
|
88
|
+
delete props[key as keyof SpaceProps];
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
return rest;
|
|
93
|
+
};
|
|
64
94
|
|
|
65
95
|
export const generatePropertySpaceStyle = (
|
|
66
96
|
theme: DefaultTheme,
|
|
@@ -78,28 +108,52 @@ export const generatePropertySpaceStyle = (
|
|
|
78
108
|
return '';
|
|
79
109
|
};
|
|
80
110
|
|
|
81
|
-
|
|
82
|
-
|
|
111
|
+
export function getResponsiveProps<T = object>(
|
|
112
|
+
{ media, ...props }: T & MediaProps<T>,
|
|
113
|
+
currentBreakpoint: Breakpoint,
|
|
114
|
+
breakpointOrder: Breakpoint[]
|
|
115
|
+
) {
|
|
116
|
+
if (!media) {
|
|
117
|
+
return props;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// Отримуємо індекс поточного breakpoint
|
|
121
|
+
const currentIndex = breakpointOrder.indexOf(currentBreakpoint);
|
|
122
|
+
|
|
123
|
+
// Створюємо результуючий об'єкт, починаючи з базових props
|
|
124
|
+
let result = { ...props };
|
|
125
|
+
|
|
126
|
+
// Застосовуємо стилі від найменшого breakpoint до поточного (mobile-first)
|
|
127
|
+
for (let i = 0; i <= currentIndex; i++) {
|
|
128
|
+
const breakpoint = breakpointOrder[i];
|
|
129
|
+
if (media[breakpoint]) {
|
|
130
|
+
result = {
|
|
131
|
+
...result,
|
|
132
|
+
...media[breakpoint],
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
return result;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
export const createComponent = <T extends FabricComponent, R = unknown>(Component: CreatedFabricComponent<T>) => {
|
|
141
|
+
return React.forwardRef<R, FabricComponent<T>>((props, ref) => {
|
|
142
|
+
const { currentBreakpoint, breakpointsOrder } = useBreakpoint();
|
|
143
|
+
const responsiveProps = useMemo(
|
|
144
|
+
() => getResponsiveProps<T>(props as T & MediaProps<T>, currentBreakpoint, breakpointsOrder),
|
|
145
|
+
[props, currentBreakpoint]
|
|
146
|
+
);
|
|
147
|
+
return <Component {...responsiveProps} ref={ref} />;
|
|
148
|
+
});
|
|
83
149
|
};
|
|
84
150
|
|
|
85
|
-
export const
|
|
151
|
+
export const createStyledComponent = <T extends object = StyledFabricComponent>(
|
|
86
152
|
component: React.ComponentType<T>,
|
|
87
|
-
options?:
|
|
153
|
+
options?: FabricStyledComponentOptions
|
|
88
154
|
) => {
|
|
89
|
-
return styled(component)<T
|
|
155
|
+
return styled(component)<StyledFabricComponent<T>>`
|
|
90
156
|
${marginStyles(options)}
|
|
91
157
|
${paddingStyles(options)}
|
|
92
158
|
`;
|
|
93
159
|
};
|
|
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
|
-
};
|
package/src/Theme/index.ts
CHANGED