From 9f60ca96c8baccf80b107fe8e41451e58b9e1409 Mon Sep 17 00:00:00 2001 From: Aron Date: Mon, 10 Jun 2024 05:55:06 +0800 Subject: [PATCH] Add segment controls and tab views --- packages/core/src/index.ts | 2 +- packages/core/src/segments.ts | 21 +++++++++-- packages/react/src/Segment.tsx | 12 +++++++ packages/react/src/Segments.tsx | 14 ++++++++ packages/react/src/TabControl.tsx | 21 +++++++++++ packages/react/src/TabPane.tsx | 17 +++++++++ packages/react/src/TabView.tsx | 34 ++++++++++++++++++ packages/react/src/index.tsx | 7 ++++ .../[locale]/components/button/metadata.ts | 2 +- .../[locale]/components/checkbox/metadata.ts | 2 +- .../components/components/Overview.tsx | 3 +- .../[locale]/components/segments/content.mdx | 9 +++++ .../[locale]/components/segments/metadata.ts | 13 +++++++ .../app/[locale]/components/segments/page.tsx | 21 +++++++++++ .../[locale]/components/select/metadata.ts | 2 +- .../[locale]/components/switch/metadata.ts | 2 +- .../[locale]/components/tab-view/content.mdx | 6 ++++ .../[locale]/components/tab-view/metadata.ts | 13 +++++++ .../app/[locale]/components/tab-view/page.tsx | 21 +++++++++++ site/app/[locale]/previews/layout.tsx | 20 ++++++++++- .../previews/segments/normal/content.tsx | 16 +++++++++ .../previews/segments/normal/page.tsx | 9 +++++ .../segments/with-leading-icon/content.tsx | 35 +++++++++++++++++++ .../segments/with-leading-icon/page.tsx | 9 +++++ .../previews/tab-view/basic/content.tsx | 23 ++++++++++++ .../[locale]/previews/tab-view/basic/page.tsx | 11 ++++++ 26 files changed, 335 insertions(+), 10 deletions(-) create mode 100644 packages/react/src/Segment.tsx create mode 100644 packages/react/src/Segments.tsx create mode 100644 packages/react/src/TabControl.tsx create mode 100644 packages/react/src/TabPane.tsx create mode 100644 packages/react/src/TabView.tsx create mode 100644 site/app/[locale]/components/segments/content.mdx create mode 100644 site/app/[locale]/components/segments/metadata.ts create mode 100644 site/app/[locale]/components/segments/page.tsx create mode 100644 site/app/[locale]/components/tab-view/content.mdx create mode 100644 site/app/[locale]/components/tab-view/metadata.ts create mode 100644 site/app/[locale]/components/tab-view/page.tsx create mode 100644 site/app/[locale]/previews/segments/normal/content.tsx create mode 100644 site/app/[locale]/previews/segments/normal/page.tsx create mode 100644 site/app/[locale]/previews/segments/with-leading-icon/content.tsx create mode 100644 site/app/[locale]/previews/segments/with-leading-icon/page.tsx create mode 100644 site/app/[locale]/previews/tab-view/basic/content.tsx create mode 100644 site/app/[locale]/previews/tab-view/basic/page.tsx diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index a4e36bd..2255124 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -2,5 +2,5 @@ export { default } from './master.css' export { default as button, buttonSizes, buttonColors } from './button' export { default as select, selectSizes } from './select' -export { default as segments } from './segments' +export { default as segments, segmentsSizes } from './segments' export { default as switch, switchSizes, switchColors } from './switch' \ No newline at end of file diff --git a/packages/core/src/segments.ts b/packages/core/src/segments.ts index da0371a..502eeac 100644 --- a/packages/core/src/segments.ts +++ b/packages/core/src/segments.ts @@ -1,8 +1,23 @@ import type { Config } from '@master/css' +export const segmentsSizes = { + sm: 'p:1 r:4 h:24 {font:12;px:10;r:4}>.segment', + md: 'p:5 r:8 h:32 {font:12;px:10;r:4}>.segment', + lg: 'p:6 r:10 h:40 {font:14;px:12;r:5}>.segment' +} + export default { styles: { - segments: 'flex bg:canvas p:5 r:2x w:fit', - segment: 'center-content flex font:12 font:medium leading:1.375rem px:3x r:1x white-space:nowrap {bg:surface;s:01;outline:1|line-lightest;fg:strong}.active' + segments: { + '': 'flex bg:canvas gap:2 w:fit', + ...segmentsSizes + }, + segment: { + '': 'center-content flex font:medium gap:6 white-space:nowrap {bg:surface;s:01;outline:1|line-lightest;fg:strong}.active', + icon: 'fg:lighter size:1em mx:-2' + } } -} as Config \ No newline at end of file +} as Config + +//
+//
\ No newline at end of file diff --git a/packages/react/src/Segment.tsx b/packages/react/src/Segment.tsx new file mode 100644 index 0000000..61f8c94 --- /dev/null +++ b/packages/react/src/Segment.tsx @@ -0,0 +1,12 @@ +import type { ButtonHTMLAttributes } from 'react' +import clsx from 'clsx' + +type SegmentProps = { + active?: boolean +} & ButtonHTMLAttributes + +const Segment = ({ className, active, ...props }: SegmentProps) => { + return