diff --git a/package.json b/package.json index fe763cf..05b5eeb 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "1byte-react-design", - "version": "1.4.12", + "version": "1.5.0", "main": "dist/index.js", "module": "dist/index.js", "types": "dist/index.d.ts", diff --git a/src/molecules/Select/Select.tsx b/src/molecules/Select/Select.tsx index 3160789..a52b2e1 100644 --- a/src/molecules/Select/Select.tsx +++ b/src/molecules/Select/Select.tsx @@ -3,7 +3,6 @@ import clsx from 'clsx'; import React, { useMemo } from 'react'; import { SelectStyledFunc } from './styles'; import { RdSelectComponent, RdSelectProps } from './types'; -import { mergeToken } from 'antd/es/theme/internal'; export const Select: RdSelectComponent = < ValueType = any, diff --git a/src/molecules/Tree/DirectoryTree.tsx b/src/molecules/Tree/DirectoryTree.tsx new file mode 100644 index 0000000..b0fa7ef --- /dev/null +++ b/src/molecules/Tree/DirectoryTree.tsx @@ -0,0 +1,23 @@ +import { BasicDataNode, DataNode } from 'antd/es/tree'; +import type RcTree from 'rc-tree'; +import { useMemo } from 'react'; +import { DirectoryTreeStylesFunc } from './styles'; +import { RdDirectoryTreeComponent, RdDirectoryTreeProps } from './types'; + +export const DirectoryTree: RdDirectoryTreeComponent = < + T extends BasicDataNode | DataNode = DataNode +>( + props: React.PropsWithChildren> & React.RefAttributes +) => { + const DirectoryTreeStyles = useMemo( + () => + DirectoryTreeStylesFunc() as (( + props: React.PropsWithChildren> & + React.RefAttributes + ) => React.ReactElement) & + Pick, + [] + ); + + return ; +}; diff --git a/src/molecules/Tree/Tree.tsx b/src/molecules/Tree/Tree.tsx new file mode 100644 index 0000000..10a5372 --- /dev/null +++ b/src/molecules/Tree/Tree.tsx @@ -0,0 +1,26 @@ +import { BasicDataNode, DataNode } from 'antd/es/tree'; +import type RcTree from 'rc-tree'; +import { useMemo } from 'react'; +import { DirectoryTree } from './DirectoryTree'; +import { TreeStylesFunc } from './styles'; +import { TreeNode } from './TreeNode'; +import { RdTreeCompoundedComponent, RdTreeProps } from './types'; + +export const TreeInternal = ({ + ...antdProps +}: RdTreeProps) => { + const TreeStyles = useMemo( + () => + TreeStylesFunc() as ( + props: React.PropsWithChildren> & React.RefAttributes + ) => React.ReactElement, + [] + ); + + return {...antdProps} />; +}; + +export const Tree = TreeInternal as RdTreeCompoundedComponent; + +Tree.TreeNode = TreeNode; +Tree.DirectoryTree = DirectoryTree; diff --git a/src/molecules/Tree/TreeNode.tsx b/src/molecules/Tree/TreeNode.tsx new file mode 100644 index 0000000..d4a1a83 --- /dev/null +++ b/src/molecules/Tree/TreeNode.tsx @@ -0,0 +1,6 @@ +import { TreeNodeStyles } from './styles'; +import { RdTreeNodeComponent } from './types'; + +export const TreeNode: RdTreeNodeComponent = props => { + return ; +}; diff --git a/src/molecules/Tree/index.tsx b/src/molecules/Tree/index.tsx new file mode 100644 index 0000000..e7cbf74 --- /dev/null +++ b/src/molecules/Tree/index.tsx @@ -0,0 +1,2 @@ +export * from './Tree'; +export * from './types'; diff --git a/src/molecules/Tree/styles.tsx b/src/molecules/Tree/styles.tsx new file mode 100644 index 0000000..6297ba1 --- /dev/null +++ b/src/molecules/Tree/styles.tsx @@ -0,0 +1,16 @@ +import styled from '@emotion/styled'; +import { Tree } from 'antd'; +import { getExcludeForwardProps } from '../../utils/styles'; +import { RdDirectoryTreeProps, RdTreeNodeProps, RdTreeProps } from './types'; +import { BasicDataNode, DataNode } from 'antd/es/tree'; + +export const TreeStylesFunc = () => + styled(Tree, { + shouldForwardProp: prop => + getExcludeForwardProps([] as (keyof RdTreeProps)[], prop), + })``; + +export const TreeNodeStyles = styled(Tree.TreeNode)``; + +export const DirectoryTreeStylesFunc = () => + styled(Tree.DirectoryTree)``; diff --git a/src/molecules/Tree/types.ts b/src/molecules/Tree/types.ts new file mode 100644 index 0000000..1ec2469 --- /dev/null +++ b/src/molecules/Tree/types.ts @@ -0,0 +1,52 @@ +import { GetProps, Tree } from 'antd'; +import { ComponentToken as TreeComponentTokenAntd } from 'antd/es/card/style'; +import { BasicDataNode, DataNode } from 'antd/es/tree'; +import type RcTree from 'rc-tree'; +import { TreeNode } from 'rc-tree'; +import { DirectoryTree } from './DirectoryTree'; +import { TreeInternal } from './Tree'; + +//#region Define Ant Design types +type TreePropsAntd = GetProps>; +type TreeNodePropsAntd = GetProps; +type DirectoryTreePropsAntd = GetProps< + typeof Tree.DirectoryTree +>; +//#endregion + +//#region Define extended component tokens +type TreeComponentTokenExtend = {}; +//#endregion + +//#region Define extended types +type TreePropsExtend = {}; + +type TreeNodePropsExtend = {}; +type DirectoryTreePropsExtend = {}; +//#endregion + +//#region Export types +export type RdTreeProps = TreePropsAntd & + TreePropsExtend; +export type RdTreeNodeProps = TreeNodePropsAntd & TreeNodePropsExtend; +export type RdDirectoryTreeProps = + DirectoryTreePropsAntd & DirectoryTreePropsExtend; + +export type RdTreeComponentToken = TreeComponentTokenAntd & TreeComponentTokenExtend; +//#endregion + +//#region Define component types +export type RdTreeInternalComponent = ( + props: React.PropsWithChildren> & React.RefAttributes +) => React.ReactElement; +export type RdTreeNodeComponent = React.FC>; +export type RdDirectoryTreeComponent = (( + props: React.PropsWithChildren> & React.RefAttributes +) => React.ReactElement) & + Pick; + +export type RdTreeCompoundedComponent = typeof TreeInternal & { + TreeNode: typeof TreeNode; + DirectoryTree: typeof DirectoryTree; +}; +//#endregion diff --git a/src/molecules/index.ts b/src/molecules/index.ts index 996857b..970dbfe 100644 --- a/src/molecules/index.ts +++ b/src/molecules/index.ts @@ -42,4 +42,5 @@ export * from './Table'; export * from './Tabs'; export * from './Tag'; export * from './Tooltip'; +export * from './Tree'; export * from './Upload'; diff --git a/src/templates/DashboardTemplate/DashboardTemplate.tsx b/src/templates/DashboardTemplate/DashboardTemplate.tsx index b79a3db..66d04b8 100644 --- a/src/templates/DashboardTemplate/DashboardTemplate.tsx +++ b/src/templates/DashboardTemplate/DashboardTemplate.tsx @@ -1,12 +1,13 @@ import { forwardRef } from 'react'; +import { Layout } from '../../molecules'; +import DashboardTemplateFooter from './Footer'; import DashboardTemplateHeader from './Header'; import DashboardTemplateSider from './Sider'; import { DashboardTemplateContent, DashboardTemplateStyles } from './styles'; import { RdDashboardTemplateComponent, RdDashboardTemplateCompoundedComponent } from './types'; -import { Layout } from '../../molecules'; const DashboardTemplateInternal: RdDashboardTemplateComponent = forwardRef((props, ref) => { - const { headerProps: headerProps, siderProps: siderProps, ...restProps } = props; + const { headerProps, siderProps, footerProps, ...restProps } = props; return ( @@ -15,7 +16,12 @@ const DashboardTemplateInternal: RdDashboardTemplateComponent = forwardRef((prop - {props.children} + + {props.children} + {footerProps !== false && ( + + )} + ); @@ -25,3 +31,4 @@ export const DashboardTemplate = DashboardTemplateInternal as RdDashboardTemplateCompoundedComponent; DashboardTemplate.Header = DashboardTemplateHeader; DashboardTemplate.Sider = DashboardTemplateSider; +DashboardTemplate.Footer = DashboardTemplateFooter; diff --git a/src/templates/DashboardTemplate/Footer/index.tsx b/src/templates/DashboardTemplate/Footer/index.tsx new file mode 100644 index 0000000..a1df46d --- /dev/null +++ b/src/templates/DashboardTemplate/Footer/index.tsx @@ -0,0 +1,20 @@ +import { forwardRef } from 'react'; +import { DashboardTemplateFooterStyles } from './styles'; +import { RdDashboardTemplateFooterComponent } from './types'; + +export const DashboardTemplateFooter: RdDashboardTemplateFooterComponent = forwardRef( + (props, ref) => { + const { children, render, ...restProps } = props; + + if (render) { + return render({ children, ...restProps }); + } + + return ( + + {children} + + ); + } +); +export default DashboardTemplateFooter; diff --git a/src/templates/DashboardTemplate/Footer/styles.tsx b/src/templates/DashboardTemplate/Footer/styles.tsx new file mode 100644 index 0000000..2b309de --- /dev/null +++ b/src/templates/DashboardTemplate/Footer/styles.tsx @@ -0,0 +1,21 @@ +import styled from '@emotion/styled'; +import { Layout } from 'antd'; +import { getComponentOrGlobalToken, getExcludeForwardProps } from '../../../utils'; +import { RdDashboardTemplateFooterProps } from './types'; +import { css } from '@emotion/react'; + +export const DashboardTemplateFooterStyles = styled(Layout.Footer, { + label: 'rd-dashboard-template-header', + shouldForwardProp: prop => + getExcludeForwardProps>( + [] as (keyof Omit)[], + prop + ), +})>` + ${() => { + return css` + border-top: 1px solid + ${getComponentOrGlobalToken('DashboardTemplate', 'colorBorderSecondary')}; + `; + }} +`; diff --git a/src/templates/DashboardTemplate/Footer/types.ts b/src/templates/DashboardTemplate/Footer/types.ts new file mode 100644 index 0000000..c588a39 --- /dev/null +++ b/src/templates/DashboardTemplate/Footer/types.ts @@ -0,0 +1,16 @@ +import { RdFooterProps, RdLayoutFooterRef } from '../../../molecules'; + +//#region Define extended types +export type DashboardTemplateFooterPropsExtend = { + fixedOnScroll?: boolean; + + render?: (props: Omit) => React.ReactNode; +}; +//#endregion + +export type RdDashboardTemplateFooterProps = RdFooterProps & DashboardTemplateFooterPropsExtend; +export type RdDashboardTemplateFooterRef = RdLayoutFooterRef & {}; + +export type RdDashboardTemplateFooterComponent = React.ForwardRefExoticComponent< + RdDashboardTemplateFooterProps & RdDashboardTemplateFooterRef +>; diff --git a/src/templates/DashboardTemplate/Sider/index.tsx b/src/templates/DashboardTemplate/Sider/index.tsx index 85045f4..f65685f 100644 --- a/src/templates/DashboardTemplate/Sider/index.tsx +++ b/src/templates/DashboardTemplate/Sider/index.tsx @@ -1,7 +1,7 @@ import { forwardRef, useState } from 'react'; +import { getComponentToken } from '../../../utils'; import { DashboardTemplateSiderStyles } from './styles'; import { RdDashboardTemplateSiderComponent } from './types'; -import { getComponentOrGlobalToken, getComponentToken } from '../../../utils'; export const DashboardTemplateSider: RdDashboardTemplateSiderComponent = forwardRef( (props, ref) => { diff --git a/src/templates/DashboardTemplate/styles.tsx b/src/templates/DashboardTemplate/styles.tsx index cfb6bd0..4b33de2 100644 --- a/src/templates/DashboardTemplate/styles.tsx +++ b/src/templates/DashboardTemplate/styles.tsx @@ -11,7 +11,7 @@ export const DashboardTemplateStyles = styled(Layout, { `} `; -export const DashboardTemplateContent = styled(Layout, { +export const DashboardTemplateContent = styled(Layout.Content, { label: 'rd-dashboard-template-content', })` ${() => css` diff --git a/src/templates/DashboardTemplate/types.ts b/src/templates/DashboardTemplate/types.ts index c61e938..5df20d3 100644 --- a/src/templates/DashboardTemplate/types.ts +++ b/src/templates/DashboardTemplate/types.ts @@ -1,4 +1,5 @@ import { RdLayoutProps, RdLayoutRef } from '../../molecules'; +import { RdDashboardTemplateFooterComponent, RdDashboardTemplateFooterProps } from './Footer/types'; import { RdDashboardTemplateHeaderComponent, RdDashboardTemplateHeaderProps } from './Header/types'; import { RdDashboardTemplateSiderComponent, RdDashboardTemplateSiderProps } from './Sider/types'; @@ -14,6 +15,7 @@ type DashboardTemplateComponentTokenExtend = { type DashboardTemplatePropsExtend = { headerProps?: RdDashboardTemplateHeaderProps; siderProps?: RdDashboardTemplateSiderProps; + footerProps?: RdDashboardTemplateFooterProps | false; test?: boolean; }; @@ -36,6 +38,7 @@ export type RdDashboardTemplateComponent = React.ForwardRefExoticComponent< export type RdDashboardTemplateCompoundedComponent = RdDashboardTemplateComponent & { Header: RdDashboardTemplateHeaderComponent; Sider: RdDashboardTemplateSiderComponent; + Footer: RdDashboardTemplateFooterComponent; // Content: RdLayoutContentComponent; // Sider: RdLayoutSiderComponent; };