Skip to content

Commit d4c71f4

Browse files
authored
Merge pull request #11 from 1Byte-Software/develop
Add templates and improve molecules
2 parents ad62f9c + da54623 commit d4c71f4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+812
-341
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "1byte-react-design",
3-
"version": "0.10.31",
3+
"version": "1.1.24-7",
44
"main": "dist/index.js",
55
"module": "dist/index.js",
66
"types": "dist/index.d.ts",

src/ConfigProviderDesign.tsx

Lines changed: 0 additions & 44 deletions
This file was deleted.

src/atomics/Flex/Flex.tsx

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
1-
import { ConfigProviderDesign } from '../../ConfigProviderDesign';
21
import { FlexStyles } from './styles';
32
import { RdFlexProps } from './types';
43

54
export const Flex = ({ ...antdProps }: RdFlexProps) => {
6-
return (
7-
<ConfigProviderDesign>
8-
<FlexStyles {...antdProps} />
9-
</ConfigProviderDesign>
10-
);
5+
return <FlexStyles {...antdProps} />;
116
};

src/index.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { theme } from 'antd';
2-
import { IRdThemeConfig } from './utils/types';
2+
import { RdThemeConfig } from './organisms';
33

44
export interface IConfig {
5-
designToken: NonNullable<IRdThemeConfig['token']>;
6-
componentToken: IRdThemeConfig['components'];
5+
designToken: NonNullable<RdThemeConfig['token']>;
6+
componentToken: RdThemeConfig['components'];
77
}
88

99
export const config: IConfig = {
@@ -14,4 +14,5 @@ export const config: IConfig = {
1414
export * from './atomics';
1515
export * from './molecules';
1616
export * from './organisms';
17+
export * from './templates';
1718
export * from './utils';

src/molecules/Button/Button.tsx

Lines changed: 66 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,74 @@
1-
import { forwardRef } from 'react';
1+
import clsx from 'clsx';
2+
import { forwardRef, useMemo, useState } from 'react';
3+
import { RdTooltipProps, Tooltip } from '../Tooltip';
24
import { ButtonGroup } from './ButtonGroup';
35
import { ButtonStyles } from './styles';
4-
import { RdButtonComponent, RdButtonCompoundedComponent } from './types';
5-
import clsx from 'clsx';
6+
import { RdButtonComponent, RdButtonCompoundedComponent, RdButtonProps } from './types';
67

78
export const ButtonInternal: RdButtonComponent = forwardRef((props, ref) => {
8-
const { rootClassName } = props;
9+
const {
10+
rootClassName,
11+
tooltip,
12+
hideTooltipWhenClick = true,
13+
onClick,
14+
onMouseLeave,
15+
...defaultProps
16+
} = props;
17+
const [isOpenTooltip, setIsOpenTooltip] = useState(false);
18+
19+
const handleClickButton: RdButtonProps['onClick'] = event => {
20+
if (hideTooltipWhenClick) {
21+
setIsOpenTooltip(false);
22+
}
23+
24+
if (onClick) {
25+
onClick(event);
26+
}
27+
};
28+
29+
const handleMouseLeave: RdButtonProps['onMouseLeave'] = event => {
30+
if (onMouseLeave) {
31+
onMouseLeave(event);
32+
}
33+
};
34+
35+
const RdButtonStyles = useMemo(() => {
36+
return (
37+
<ButtonStyles
38+
rootClassName={clsx('rd-button', rootClassName)}
39+
ref={ref}
40+
onMouseLeave={handleMouseLeave}
41+
onClick={handleClickButton}
42+
{...defaultProps}
43+
/>
44+
);
45+
}, [defaultProps, rootClassName, handleClickButton, handleMouseLeave]);
46+
47+
if (tooltip) {
48+
const tooltipProps: RdTooltipProps = hideTooltipWhenClick
49+
? {
50+
open: isOpenTooltip,
51+
onOpenChange: visible => setIsOpenTooltip(visible),
52+
}
53+
: {};
54+
55+
if (typeof tooltip === 'string') {
56+
return (
57+
<Tooltip {...tooltipProps} title={tooltip}>
58+
{RdButtonStyles}
59+
</Tooltip>
60+
);
61+
}
62+
63+
return (
64+
<Tooltip {...tooltipProps} {...tooltip}>
65+
{RdButtonStyles}
66+
</Tooltip>
67+
);
68+
}
969

10-
return <ButtonStyles rootClassName={clsx('rd-button', rootClassName)} ref={ref} {...props} />;
70+
return RdButtonStyles;
1171
});
1272

1373
export const Button = ButtonInternal as RdButtonCompoundedComponent;
14-
Button.Group = ButtonGroup;
74+
Button.Group = ButtonGroup;

src/molecules/Button/styles.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ export const ButtonStyles = styled(Button as RdButtonComponent, {
99
getExcludeForwardProps<RdButtonProps>(['fullWidth'] as (keyof RdButtonProps)[], prop),
1010
})<RdButtonProps>`
1111
${({ fullWidth }) => fullWidth && fullWidthCSS}
12-
1312
${({ color }) => {
1413
switch (color) {
1514
case 'second':
@@ -28,8 +27,7 @@ export const ButtonStyles = styled(Button as RdButtonComponent, {
2827
return color;
2928
}
3029
}}
31-
32-
${({ align }) => {
30+
${({ align }) => {
3331
switch (align) {
3432
case 'left':
3533
return css`
@@ -46,7 +44,7 @@ export const ButtonStyles = styled(Button as RdButtonComponent, {
4644
default:
4745
return null;
4846
}
49-
}}
47+
}};
5048
`;
5149
export const ButtonGroupStyles = styled(Button.Group)<RdButtonGroupProps>``;
5250

src/molecules/Button/types.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Button, ButtonProps, GetProps } from 'antd';
22
import { ComponentToken as ButtonComponentTokenAntd } from 'antd/es/button/style';
33
import { ButtonInternal } from './Button';
44
import { ButtonGroup } from './ButtonGroup';
5+
import { RdTooltipProps } from '../Tooltip';
56

67
//#region Define Ant Design types
78
type ButtonPropsAntd = GetProps<typeof Button>;
@@ -37,6 +38,18 @@ type ButtonPropsExtend = {
3738
* Align content in the button.
3839
*/
3940
align?: 'left' | 'center' | 'right';
41+
42+
/**
43+
* Configuration for the tooltip displayed when hovering over the button.
44+
* @see string | RdTooltipProps for more details on available options.
45+
*/
46+
tooltip?: string | RdTooltipProps;
47+
48+
/**
49+
* If `true`, the button will auto hide when the button is clicked.
50+
* @default true
51+
*/
52+
hideTooltipWhenClick?: boolean;
4053
};
4154

4255
type ButtonGroupPropsExtend = {};

src/molecules/Button/useExtendColor.ts

Lines changed: 0 additions & 17 deletions
This file was deleted.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { forwardRef } from 'react';
2+
import { CarouselStyles } from './styles';
3+
import { RdCarouselComponent } from './types';
4+
5+
export const Carousel: RdCarouselComponent = forwardRef((props, ref) => {
6+
return <CarouselStyles ref={ref} {...props} />;
7+
});

src/molecules/Carousel/index.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export * from './Carousel';
2+
export * from './types';

0 commit comments

Comments
 (0)