Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "1byte-react-design",
"version": "1.1.24-7",
"version": "1.3.22-15",
"main": "dist/index.js",
"module": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
22 changes: 19 additions & 3 deletions src/atomics/Typography/styles.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,30 @@ export const TypographyTitleStyles = styled(Typography.Title, {
}}
`;

export const TypographyTextStyles = styled(Typography.Text)<Pick<RdTypographyTextProps, 'size'>>`
export const TypographyTextStyles = styled(Typography.Text, {
shouldForwardProp: prop =>
getExcludeForwardProps<RdTypographyTextProps>(
['noWrap', 'size'] as (keyof RdTypographyTextProps)[],
prop
),
})<Pick<RdTypographyTextProps, 'size' | 'noWrap'>>`
${({ size }) => {
switch (size) {
case 'small':
return `
font-size: ${getComponentOrGlobalToken('Typography', 'fontSizeSM')}px;
`;
// Case normal is the default size
}
}}

${({ noWrap }) => {
return (
noWrap &&
css`
text-wrap: nowrap;
`
);
}}
`;

export const TypographyParagraphStyles = styled(Typography.Paragraph, {
Expand All @@ -47,7 +61,9 @@ export const TypographyParagraphStyles = styled(Typography.Paragraph, {
return (
minRows &&
css`
min-height: ${Number(getComponentOrGlobalToken('Typography', 'lineHeight')) * Number(getComponentOrGlobalToken('Typography', 'fontSize')) * minRows}px;
min-height: ${Number(getComponentOrGlobalToken('Typography', 'lineHeight')) *
Number(getComponentOrGlobalToken('Typography', 'fontSize')) *
minRows}px;
`
);
}}
Expand Down
11 changes: 9 additions & 2 deletions src/atomics/Typography/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,20 @@ type TypographyParagraphPropsExtend = TypographyBaseProps & {
};
type TypographyTextPropsExtend = TypographyBaseProps & {
/**
* @description The size of the text.
* If true, the text will not wrap to the next line and instead will be truncated with an ellipsis when it overflows.
* This is useful when you want to keep the text in a single line.
* @default false
*/
noWrap?: boolean;

/**
* The size of the text.
* @default "normal"
*/
size?: 'small' | 'normal';

/**
* @description Callback function that is triggered when the text value changes.
* Callback function that is triggered when the text value changes.
* @param value The new value of the text.
*/
onChange?: (value: string) => void;
Expand Down
19 changes: 18 additions & 1 deletion src/molecules/ColorPicker/styles.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,21 @@
import styled from '@emotion/styled';
import { ColorPicker } from 'antd';
import { getExcludeForwardProps } from '../../utils';
import { RdColorPickerProps } from './types';

export const ColorPickerStyles = styled(ColorPicker)``;
export const ColorPickerStyles = styled(ColorPicker, {
shouldForwardProp: prop =>
getExcludeForwardProps<RdColorPickerProps>(
['readonly'] as (keyof RdColorPickerProps)[],
prop
),
})<RdColorPickerProps>`
${({ readonly }) => {
return (
readonly &&
`
pointer-events: none;
`
);
}}
`;
10 changes: 9 additions & 1 deletion src/molecules/ColorPicker/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,15 @@ type ColorPickerComponentTokenExtend = {};
//#endregion

//#region Define extended types
type ColorPickerPropsExtend = {};
type ColorPickerPropsExtend = {
/**
* Determines whether the color picker should be in a read-only state.
* When set to `true`, user interactions such as selecting or changing colors are disabled.
*
* @default false
*/
readonly?: boolean;
};
//#endregion

//#region Export types
Expand Down
3 changes: 2 additions & 1 deletion src/molecules/Divider/Divider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ import { DividerStyles } from './styles';
import { RdDividerComponent } from './types';

export const Divider: RdDividerComponent = props => {
return <DividerStyles {...props} />;
const { disableMargin = false, ...antdProps } = props;
return <DividerStyles disableMargin={disableMargin} {...antdProps} />;
};
14 changes: 13 additions & 1 deletion src/molecules/Divider/styles.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@
import styled from '@emotion/styled';
import { Divider } from 'antd';
import { getExcludeForwardProps } from '../../utils';
import { RdDividerProps } from './types';
import { css } from '@emotion/react';

export const DividerStyles = styled(Divider)``;
export const DividerStyles = styled(Divider, {
shouldForwardProp: prop =>
getExcludeForwardProps<RdDividerProps>(['disableMargin'] as (keyof RdDividerProps)[], prop),
})<RdDividerProps>`
${({ disableMargin }) => {
return disableMargin && css`
margin: 0;
`;
}}
`;
8 changes: 7 additions & 1 deletion src/molecules/Divider/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,13 @@ type DividerComponentTokenExtend = {};
//#endregion

//#region Define extended types
type DividerPropsExtend = {};
type DividerPropsExtend = {
/**
* If `true`, removes the default margin of the Divider.
* @default false.
*/
disableMargin?: boolean;
};
//#endregion

//#region Export types
Expand Down
7 changes: 6 additions & 1 deletion src/molecules/Pagination/Pagination.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import { useContext } from 'react';
import { ConfigProvider } from '../../organisms';
import { PaginationStyled } from './styles';
import { RdPaginationComponent } from './types';

export const Pagination: RdPaginationComponent = props => {
return <PaginationStyled {...props} />;
const { pagination: defaultPaginationProps } = useContext(ConfigProvider.ConfigContext);
const { pageSizeOptions } = defaultPaginationProps || {};

return <PaginationStyled pageSizeOptions={pageSizeOptions} {...props} />;
};
1 change: 1 addition & 0 deletions src/molecules/Select/index.tsx
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from './strategies';
export * from './Select';
export * from './types';
1 change: 1 addition & 0 deletions src/molecules/Select/strategies/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './selectFilterOptionByLabel';
8 changes: 8 additions & 0 deletions src/molecules/Select/strategies/selectFilterOptionByLabel.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { RdSelectProps } from '../types';

export const selectFilterOptionByLabel: RdSelectProps['filterOption'] = (input, option) => {
return (
option?.props?.children?.toLowerCase().indexOf(input.toLowerCase()) >= 0 ||
option?.props?.label?.toLowerCase().indexOf(input.toLowerCase()) >= 0
);
};
6 changes: 6 additions & 0 deletions src/molecules/Steps/Steps.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { StepsStyles } from './styles';
import { RdStepsComponent } from './types';

export const Steps: RdStepsComponent = props => {
return <StepsStyles {...props} />;
};
2 changes: 2 additions & 0 deletions src/molecules/Steps/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './Steps';
export * from './types';
4 changes: 4 additions & 0 deletions src/molecules/Steps/styles.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import styled from '@emotion/styled';
import { Steps } from 'antd';

export const StepsStyles = styled(Steps)``;
25 changes: 25 additions & 0 deletions src/molecules/Steps/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { GetProps, Steps } from 'antd';
import { ComponentToken as StepsComponentTokenAntd } from 'antd/es/collapse/style';

//#region Define Ant Design types
type StepsPropsAntd = GetProps<typeof Steps>;

//#endregion

//#region Define extended component tokens
type StepsComponentTokenExtend = {};
//#endregion

//#region Define extended types
type StepsPropsExtend = {};
//#endregion

//#region Export types
export type RdStepsProps = StepsPropsAntd & StepsPropsExtend;

export type RdStepsComponentToken = StepsComponentTokenAntd & StepsComponentTokenExtend;
//#endregion

//#region Define component types
export type RdStepsComponent = React.FC<RdStepsProps>;
//#endregion
22 changes: 19 additions & 3 deletions src/molecules/Table/Table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,23 @@ import { AnyObject } from 'antd/es/_util/type';
import { RowSortable } from './sortable';
import { TableStyledFunc } from './styles';
import { RdTableProps } from './types';
import { useContext, useMemo } from 'react';
import { ConfigProvider } from '../../organisms';

export const Table = <RecordType extends AnyObject = AnyObject>(
props: RdTableProps<RecordType>
) => {
const { allowSort = false, onChangeSort, ...antdProps } = props;
const { allowSort = false, pagination, onChangeSort, ...antdProps } = props;
const { table: defaultTableProps } = useContext(ConfigProvider.ConfigContext);
const { pagination: defaultPagination } = defaultTableProps || {};

const paginationWithDefault = useMemo(() => {
return {
...defaultPagination,
...pagination,
};
}, [pagination, defaultPagination]);

const TableStyled = TableStyledFunc<RecordType>();

if (allowSort && props.rowKey) {
Expand All @@ -32,11 +44,15 @@ export const Table = <RecordType extends AnyObject = AnyObject>(
items={dataSource.map(i => i[props.rowKey as string])}
strategy={verticalListSortingStrategy}
>
<TableStyled components={{ body: { row: RowSortable } }} {...antdProps} />
<TableStyled
components={{ body: { row: RowSortable } }}
pagination={paginationWithDefault}
{...antdProps}
/>
</SortableContext>
</DndContext>
);
}

return <TableStyled {...antdProps} />;
return <TableStyled pagination={paginationWithDefault} {...antdProps} />;
};
2 changes: 2 additions & 0 deletions src/molecules/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export * from './Card';
export * from './Carousel';
export * from './Checkbox';
export * from './Collapse';
export * from './ColorPicker';
export * from './DatePicker';
export * from './Divider';
export * from './Drawer';
Expand All @@ -35,6 +36,7 @@ export * from './Skeleton';
export * from './Slider';
export * from './Space';
export * from './Spin';
export * from './Steps';
export * from './Switch';
export * from './Table';
export * from './Tabs';
Expand Down
6 changes: 4 additions & 2 deletions src/molecules/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { RdBadgeComponentToken } from './Badge';
import { RdBreadcrumbComponentToken } from './Breadcrumb';
import { RdButtonComponentToken } from './Button';
import { RdCardComponentToken } from './Card';
import { RdCarouselComponentToken } from './Carousel';
import { CheckboxComponentToken } from './Checkbox';
import { RdCollapseComponentToken } from './Collapse';
import { RdColorPickerComponentToken } from './ColorPicker';
Expand Down Expand Up @@ -34,6 +35,7 @@ import { RdSkeletonComponentToken } from './Skeleton';
import { RdSliderComponentToken } from './Slider';
import { RdSpaceComponentToken } from './Space';
import { RdSpinComponentToken } from './Spin';
import { RdStepsComponentToken } from './Steps';
import { RdSwitchComponentToken } from './Switch';
import { RdTableComponentToken } from './Table';
import { RdTabsComponentToken } from './Tabs';
Expand All @@ -51,7 +53,7 @@ export interface RdMoleculesTokenMap {
Button?: RdButtonComponentToken;
Breadcrumb?: RdBreadcrumbComponentToken;
Card?: RdCardComponentToken;
// Carousel?: CarouselComponentToken;
Carousel?: RdCarouselComponentToken;
// Cascader?: CascaderComponentToken;
Checkbox?: CheckboxComponentToken;
ColorPicker?: RdColorPickerComponentToken;
Expand Down Expand Up @@ -95,7 +97,7 @@ export interface RdMoleculesTokenMap {
// Transfer?: TransferComponentToken;
Tabs?: RdTabsComponentToken;
// Calendar?: CalendarComponentToken;
// Steps?: StepsComponentToken;
Steps?: RdStepsComponentToken;
Menu?: RdMenuComponentToken;
Modal?: RdModalComponentToken;
Message?: RdMessageComponentToken;
Expand Down
18 changes: 14 additions & 4 deletions src/organisms/ConfigProvider/ConfigProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
import { ConfigProvider as ConfigProviderAntd } from 'antd';
import { RdConfigProviderCompoundedComponent, RdConfigProviderProps } from './types';
import { ConfigContext } from './context';
import { RdConfigConsumerProps } from './context/types';
import { RdConfigProviderCompoundedComponent, RdConfigProviderInternalComponent } from './types';

export const ConfigProviderInternal = ({ ...antdProps }: RdConfigProviderProps) => {
return <ConfigProviderAntd {...antdProps} />;
export const ConfigProviderInternal: RdConfigProviderInternalComponent = props => {
return (
<ConfigContext.Provider
value={{
...(props as RdConfigConsumerProps),
}}
>
<ConfigProviderAntd {...props} />
</ConfigContext.Provider>
);
};

export const ConfigProvider = ConfigProviderInternal as RdConfigProviderCompoundedComponent;

ConfigProvider.ConfigContext = ConfigProviderAntd.ConfigContext;
ConfigProvider.ConfigContext = ConfigContext;
ConfigProvider.SizeContext = ConfigProviderAntd.SizeContext;
ConfigProvider.config = ConfigProviderAntd.config;
ConfigProvider.useConfig = ConfigProviderAntd.useConfig;
14 changes: 14 additions & 0 deletions src/organisms/ConfigProvider/configs/pagination.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { PaginationConfig } from 'antd/es/config-provider/context';
import { RdPaginationProps } from '../../../molecules';

//#region Define Ant Design types
type PaginationConfigAntd = PaginationConfig;
//#endregion

//#region Define extended types
interface PaginationConfigExtend extends Pick<RdPaginationProps, 'pageSizeOptions'> {}
//#endregion

//#region Export types
export type RdPaginationConfig = PaginationConfigAntd & PaginationConfigExtend;
//#endregion
14 changes: 14 additions & 0 deletions src/organisms/ConfigProvider/configs/table.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { TableConfig } from 'antd/es/config-provider/context';
import { RdTableProps } from '../../../molecules';

//#region Define Ant Design types
type TableConfigAntd = TableConfig;
//#endregion

//#region Define extended types
interface TableConfigExtend extends Pick<RdTableProps, 'pagination'> {}
//#endregion

//#region Export types
export type RdTableConfig = TableConfigAntd & TableConfigExtend;
//#endregion
2 changes: 2 additions & 0 deletions src/organisms/ConfigProvider/context/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export const defaultPrefixCls = 'ant';
export const defaultIconPrefixCls = 'anticon';
8 changes: 8 additions & 0 deletions src/organisms/ConfigProvider/context/helper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { defaultPrefixCls } from './constants';

export const defaultGetPrefixCls = (suffixCls?: string, customizePrefixCls?: string) => {
if (customizePrefixCls) {
return customizePrefixCls;
}
return suffixCls ? `${defaultPrefixCls}-${suffixCls}` : defaultPrefixCls;
};
10 changes: 10 additions & 0 deletions src/organisms/ConfigProvider/context/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import React from 'react';
import { defaultIconPrefixCls, defaultPrefixCls } from './constants';
import { RdConfigConsumerProps } from './types';
import { defaultGetPrefixCls } from './helper';

export const ConfigContext = React.createContext<RdConfigConsumerProps>({
// We provide a default function for Context without provider
getPrefixCls: defaultGetPrefixCls,
iconPrefixCls: defaultIconPrefixCls,
});
Loading
Loading