From c1c72ed1e42bd87ec4ddd1cf567b5afe1a2f480d Mon Sep 17 00:00:00 2001 From: South Drifted Date: Sun, 14 Jan 2024 01:31:01 +0000 Subject: [PATCH] [refactor] rewrite Core codes of Table & Dropdown components --- package.json | 2 +- source/Dropdown.tsx | 105 ++++++++++++++++++++++++++++++++++++++++++++ source/Table.tsx | 60 +++++++++++++++++++++++++ source/index.ts | 8 ++-- 4 files changed, 171 insertions(+), 4 deletions(-) create mode 100644 source/Dropdown.tsx create mode 100644 source/Table.tsx diff --git a/package.json b/package.json index a59971bb..e850231c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "boot-cell", - "version": "2.0.0-beta.0", + "version": "2.0.0-beta.2", "license": "LGPL-3.0", "author": "shiy2008@gmail.com", "description": "Web Components UI library based on WebCell v3, BootStrap v5, BootStrap Icon v1 & FontAwesome v6", diff --git a/source/Dropdown.tsx b/source/Dropdown.tsx new file mode 100644 index 00000000..4b2bc120 --- /dev/null +++ b/source/Dropdown.tsx @@ -0,0 +1,105 @@ +import classNames from 'classnames'; +import { JsxChildren } from 'dom-renderer'; +import { observable } from 'mobx'; +import { FC, WebCellProps, attribute, component, observer } from 'web-cell'; + +import { Button, ButtonProps } from './Button'; + +export const Dropdown: FC> = ({ + className = '', + children, + ...props +}) => ( +
+ {children} +
+); + +export const DropdownToggle: FC = ({ + className = '', + children, + ...props +}) => ( + +); + +export const DropdownMenu: FC = ({ + className = '', + children, + ...props +}) => ( + +); + +export const DropdownItem: FC> = ({ + className = '', + children, + ...props +}) => ( + + {children} + +); + +export interface DropdownButtonProps extends WebCellProps, ButtonProps { + caption: JsxChildren; +} + +@component({ + tagName: 'dropdown-button', + mode: 'open' +}) +@observer +export class DropdownButton extends HTMLElement { + declare props: DropdownButtonProps; + + @attribute + @observable + accessor variant: ButtonProps['variant']; + + @attribute + @observable + accessor size: ButtonProps['size']; + + @observable + accessor caption: JsxChildren; + + @attribute + @observable + accessor show = false; + + renderContent() { + const { variant, size, caption, show } = this; + + return ( + + (this.show = !show)} + > + {caption} + + + + + + ); + } + + render() { + return ( + <> + + {this.renderContent()} + + ); + } +} diff --git a/source/Table.tsx b/source/Table.tsx new file mode 100644 index 00000000..30901a91 --- /dev/null +++ b/source/Table.tsx @@ -0,0 +1,60 @@ +import classNames from 'classnames'; +import { FC, WebCellProps } from 'web-cell'; + +import { Color, Size } from './type'; + +export interface TableProps extends WebCellProps { + variant?: Color; + size?: 'sm'; + responsive?: boolean | Size; + striped?: boolean | 'columns'; + hover?: boolean; + bordered?: boolean; + borderless?: boolean; + caption?: 'top'; +} + +export const Table: FC = ({ + className, + variant, + size, + responsive, + striped, + hover, + bordered, + borderless, + caption, + children, + ...props +}) => { + const table = ( + + {children} +
+ ); + + return responsive ? ( +
+ {table} +
+ ) : ( + table + ); +}; diff --git a/source/index.ts b/source/index.ts index 06f545be..e94eacd9 100644 --- a/source/index.ts +++ b/source/index.ts @@ -1,8 +1,10 @@ export * from './type'; export * from './Grid'; +export * from './Table'; +export * from './Form'; +export * from './Button'; +export * from './Icon'; +export * from './Dropdown'; export * from './Nav'; export * from './Navbar'; export * from './Offcanvas'; -export * from './Icon'; -export * from './Button'; -export * from './Form';