Skip to content

Commit

Permalink
[refactor] upgrade List Group, Button Group & Toggle Button components
Browse files Browse the repository at this point in the history
[optimize] Module folder structure
  • Loading branch information
TechQuery committed Jun 16, 2024
1 parent d5ce2ac commit d3e8905
Show file tree
Hide file tree
Showing 30 changed files with 184 additions and 257 deletions.
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "boot-cell",
"version": "2.0.0-beta.26",
"version": "2.0.0-beta.28",
"license": "LGPL-3.0",
"author": "[email protected]",
"description": "Web Components UI library based on WebCell v3, BootStrap v5, BootStrap Icon v1 & FontAwesome v6",
Expand All @@ -26,7 +26,7 @@
"dependencies": {
"@swc/helpers": "^0.5.11",
"classnames": "^2.5.1",
"dom-renderer": "^2.1.7",
"dom-renderer": "^2.1.8",
"mobx": "^6.12.4",
"regenerator-runtime": "^0.14.1",
"web-cell": "^3.0.0-rc.16",
Expand Down Expand Up @@ -64,10 +64,10 @@
"open-cli": "^8.0.0",
"parcel": "~2.12.0",
"prettier": "^3.3.2",
"ts-jest": "^29.1.4",
"ts-jest": "^29.1.5",
"ts-node": "^10.9.2",
"typedoc": "^0.25.13",
"typedoc-plugin-mdn-links": "^3.1.29",
"typedoc-plugin-mdn-links": "^3.1.30",
"typescript": "~5.4.5"
},
"scripts": {
Expand Down
32 changes: 16 additions & 16 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions source/CountDown.tsx → source/Calendar/CountDown.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { computed, observable } from 'mobx';
import { WebCell, attribute, component, observer } from 'web-cell';

import { Status } from './type';
import { Status } from '../type';

interface TimeUnit {
scale: number;
Expand Down Expand Up @@ -101,7 +101,7 @@ export class CountDown extends HTMLElement implements WebCell<CountDownProps> {
<ol className="list-inline text-white">
{this.timeSections.map(({ value, label }, index) => (
<li
key={value}
key={label}
className={`list-inline-item fs-1 bg-${colors[index]} d-inline-flex align-items-center justify-content-center rounded-4`}
style={{ width: '5.5rem', height: '5.5rem' }}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import {
splitArray
} from 'web-utility';

import { Badge } from './Reminder';
import { Button, ButtonProps } from './Button';
import { Table, TableProps } from './Content';
import { Badge } from '../Reminder';
import { Button, ButtonProps } from '../Form/Button';
import { Table, TableProps } from '../Content';

export interface DateData {
date: TimeData;
Expand Down
2 changes: 1 addition & 1 deletion source/Content/Accordion.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
reaction
} from 'web-cell';

import { CollapseProps, Collapse } from './Collapse';
import { CollapseProps, Collapse } from '../Layout/Collapse';

export const AccordionItem: FC<WebCellProps<HTMLDivElement>> = ({
className = '',
Expand Down
2 changes: 1 addition & 1 deletion source/Content/Card.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import classNames from 'classnames';
import { FC, WebCellProps } from 'web-cell';

import { Image, ImageProps } from '../Image';
import { Image, ImageProps } from '../Media/Image';
import { TextColor, PositionY } from '../type';

export interface CardProps extends WebCellProps<HTMLDivElement> {
Expand Down
2 changes: 1 addition & 1 deletion source/Content/Jumbotron.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { JsxChildren } from 'dom-renderer';
import { FC } from 'web-cell';

import { BackgroundColor } from '../type';
import { Container, ContainerProps } from '../Grid';
import { Container, ContainerProps } from '../Layout/Grid';

export interface JumbotronProps
extends Omit<ContainerProps, 'title'>,
Expand Down
65 changes: 65 additions & 0 deletions source/Content/ListGroup.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import classNames from 'classnames';
import { FC, WebCellProps } from 'web-cell';

import { Size, Status, Theme } from '../type';

export interface ListGroupProps extends WebCellProps<HTMLDivElement> {
variant?: 'flush';
numbered?: boolean;
horizontal?: true | Size;
}

export const ListGroup: FC<ListGroupProps> = ({
className = '',
variant,
numbered,
horizontal,
children,
...props
}) => (
<div
className={classNames(
'list-group',
variant && `list-group-${variant}`,
numbered && `list-group-numbered`,
horizontal &&
`list-group-horizontal${horizontal === true ? '' : `-${horizontal}`}`,
className
)}
{...props}
>
{children}
</div>
);

export interface ListGroupItemProps
extends WebCellProps<HTMLAnchorElement>,
Partial<Record<'active' | 'disabled', boolean>> {
variant?: keyof typeof Status | keyof typeof Theme;
}

export const ListGroupItem: FC<ListGroupItemProps> = ({
className = '',
variant,
href,
active,
disabled,
children,
...props
}) => (
<a
className={classNames(
'list-group-item',
variant && `list-group-item-${variant}`,
href && 'list-group-item-action',
{ active, disabled },
disabled && 'pe-none',
className
)}
ariaCurrent={active ? 'true' : undefined}
ariaDisabled={disabled ? 'true' : undefined}
{...{ href, ...props }}
>
{children}
</a>
);
2 changes: 1 addition & 1 deletion source/Content/Tabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
reaction
} from 'web-cell';

import { Nav, NavLink } from '../Nav';
import { Nav, NavLink } from '../Navigator/Nav';

export interface TabProps {
caption: JsxChildren;
Expand Down
3 changes: 1 addition & 2 deletions source/Content/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
export * from './ListGroup';
export * from './Table';
export * from './Jumbotron';
export * from './Card';
export * from './MediaObject';
export * from './ScrollBoundary';
export * from './Collapse';
export * from './Accordion';
export * from './Tabs';
29 changes: 26 additions & 3 deletions source/Button.tsx → source/Form/Button.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import classNames from 'classnames';
import { JsxChildren, VNode } from 'dom-renderer';
import { FC, WebCellProps } from 'web-cell';
import { uniqueID } from 'web-utility';

import { FormControlProps } from './Form';
import { Icon, IconProps } from './Reminder';
import { TextColor } from './type';
import { FormCheckProps, FormControlProps } from './Form';
import { Icon, IconProps } from '../Reminder';
import { TextColor } from '../type';

export interface ButtonProps
extends WebCellProps<HTMLButtonElement>,
Expand Down Expand Up @@ -82,3 +83,25 @@ export const CloseButton: FC<WebCellProps<HTMLButtonElement>> = ({
{...props}
/>
);

export interface ToggleButtonProps
extends WebCellProps<HTMLInputElement>,
Pick<ButtonProps, 'variant'> {
type: Exclude<FormCheckProps['type'], 'switch'>;
}

export const ToggleButton: FC<ToggleButtonProps> = ({
className = '',
id = uniqueID(),
variant = 'primary',
children,
...props
}) => (
<>
<input className="btn-check" id={id} autocomplete="off" {...props} />

<label className={`btn btn-${variant} ${className}`} htmlFor={id}>
{children}
</label>
</>
);
39 changes: 39 additions & 0 deletions source/Form/ButtonGroup.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import classNames from 'classnames';
import { FC, WebCellProps } from 'web-cell';

export interface ButtonGroupProps extends WebCellProps<HTMLDivElement> {
vertical?: boolean;
size?: 'sm' | 'lg';
}

export const ButtonGroup: FC<ButtonGroupProps> = ({
className = '',
vertical,
size,
children,
...props
}) => (
<div
className={classNames(
`btn-group${vertical ? '-vertical' : ''}`,
size && `btn-group-${size}`,
className
)}
role="group"
{...props}
>
{children}
</div>
);

export type ButtonToolbarProps = WebCellProps<HTMLDivElement>;

export const ButtonToolbar: FC<ButtonToolbarProps> = ({
className = '',
children,
...props
}) => (
<div className={`btn-toolbar ${className}`} role="toolbar" {...props}>
{children}
</div>
);
4 changes: 2 additions & 2 deletions source/Form.tsx → source/Form/Form.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import classNames from 'classnames';
import { VNode } from 'dom-renderer';
import { JsxChildren } from 'dom-renderer';
import { FC, WebCellProps } from 'web-cell';
import { uniqueID } from 'web-utility';

Expand Down Expand Up @@ -108,7 +108,7 @@ export interface FormCheckProps extends WebCellProps<HTMLInputElement> {
type: 'radio' | 'checkbox' | 'switch';
inline?: boolean;
reverse?: boolean;
label?: VNode;
label?: JsxChildren;
}

export const FormCheck: FC<FormCheckProps> = ({
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion source/Grid.tsx → source/Layout/Grid.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { JsxProps } from 'dom-renderer';
import { FC } from 'web-cell';

import { Size } from './type';
import { Size } from '../type';

export interface ContainerProps extends JsxProps<HTMLDivElement> {
fluid?: boolean | Size;
Expand Down
2 changes: 1 addition & 1 deletion source/Offcanvas.tsx → source/Layout/Offcanvas.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import classNames from 'classnames';
import { FC, WebCellProps } from 'web-cell';
import { uniqueID } from 'web-utility';

import { CloseButton } from './Button';
import { CloseButton } from '../Form/Button';

export const OffcanvasTitle: FC<WebCellProps<HTMLHeadingElement>> = ({
className = '',
Expand Down
File renamed without changes.
File renamed without changes.
5 changes: 5 additions & 0 deletions source/Layout/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export * from './Ratio';
export * from './Grid';
export * from './ScrollBoundary';
export * from './Collapse';
export * from './Offcanvas';
File renamed without changes.
File renamed without changes.
1 change: 0 additions & 1 deletion v1/Media/index.ts → source/Media/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
export * from './Image';
export * from './Embed';
export * from './Carousel';
Loading

0 comments on commit d3e8905

Please sign in to comment.