-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
26 changed files
with
335 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} as Config | ||
|
||
// <div class="segment-tab"> | ||
// <div class="segment-tab"> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import type { ButtonHTMLAttributes } from 'react' | ||
import clsx from 'clsx' | ||
|
||
type SegmentProps = { | ||
active?: boolean | ||
} & ButtonHTMLAttributes<HTMLButtonElement> | ||
|
||
const Segment = ({ className, active, ...props }: SegmentProps) => { | ||
return <button {...props} className={clsx('segment', className, active && 'active')} /> | ||
} | ||
|
||
export default Segment |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import type { HTMLAttributes } from 'react' | ||
import type { segmentsSizes } from '@master/ui' | ||
import clsx from 'clsx' | ||
|
||
type SegmentsProps = { | ||
// eslint-disable-next-line @typescript-eslint/ban-types | ||
size?: (keyof typeof segmentsSizes) | (string & {}) | ||
} & HTMLAttributes<HTMLDivElement> | ||
|
||
const Segments = ({ className, size = 'md', ...props }: SegmentsProps) => { | ||
return <div {...props} className={clsx('segments', size && `segments-${size}`, className)} /> | ||
} | ||
|
||
export default Segments |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
'use client' | ||
|
||
import { type ElementType, type ComponentPropsWithoutRef, useMemo } from 'react' | ||
import clsx from 'clsx' | ||
import { useTabView } from './TabView' | ||
|
||
type TabControlProps<T extends ElementType> = { | ||
name: string | ||
as?: T | ||
disabled?: boolean | ||
} & ComponentPropsWithoutRef<T> | ||
|
||
export default function TabControl<T extends ElementType = 'button'>({ as, className, disabled, ...props }: TabControlProps<T>) { | ||
const tabView = useTabView() | ||
const Component = as || 'button' | ||
return <Component {...props} | ||
className={clsx(!Component && 'tab', className, tabView.activeTab === props.name && 'active')} | ||
onClick={() => tabView.setActiveTab(props.name)} | ||
disabled={Component === 'button' ? disabled : undefined} | ||
/> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
'use client' | ||
|
||
import type { ElementType, ComponentPropsWithoutRef } from 'react' | ||
import { useTabView } from './TabView' | ||
|
||
type TabPaneProps<T extends ElementType> = { | ||
name: string | ||
as?: T | ||
} & ComponentPropsWithoutRef<T> | ||
|
||
const TabPane = <T extends ElementType = 'div'>({ as, ...props }: TabPaneProps<T>) => { | ||
const tabView = useTabView() | ||
const Component = as || 'div' | ||
return <Component {...props} hidden={tabView.activeTab !== props.name} /> | ||
} | ||
|
||
export default TabPane |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
'use client' | ||
|
||
import { FC, ReactNode, createContext, useContext, useState } from 'react' | ||
|
||
type TabViewContextType = { | ||
activeTab?: string | ||
setActiveTab: (tab: string) => void | ||
}; | ||
|
||
export const TabViewContext = createContext<TabViewContextType | undefined>(undefined) | ||
|
||
export const useTabView = () => { | ||
const context = useContext(TabViewContext) | ||
if (context === undefined) { | ||
throw new Error('useTabView must be used within a TabView') | ||
} | ||
return context | ||
} | ||
|
||
type TabViewProps = { | ||
activeTab?: string | ||
children: ReactNode | ||
} | ||
|
||
const TabView: FC<TabViewProps> = (props) => { | ||
const [activeTab, setActiveTab] = useState<string | undefined>(props.activeTab) | ||
return ( | ||
<TabViewContext.Provider value={{ activeTab, setActiveTab }}> | ||
{props.children} | ||
</TabViewContext.Provider> | ||
) | ||
} | ||
|
||
export default TabView |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
## Normal | ||
<CodePreview src="segments/normal" | ||
raw={require('!!raw-loader!../../previews/segments/normal/content').default} | ||
children={require('../../previews/segments/normal/content').default()} /> | ||
|
||
## With leading icon | ||
<CodePreview src="segments/with-leading-icon" | ||
raw={require('!!raw-loader!../../previews/segments/with-leading-icon/content').default} | ||
children={require('../../previews/segments/with-leading-icon/content').default()} /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import define from 'internal/utils/metadata' | ||
|
||
const metadata = define({ | ||
title: 'Segments', | ||
description: 'A set of segment controls, each of which functions as a button.', | ||
category: 'Control', | ||
openGraph: { | ||
images: new URL('~/site/public/images/components/select.jpg', import.meta.url).toString() | ||
}, | ||
filename: import.meta.url | ||
}) | ||
|
||
export default metadata |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import Layout from 'internal/layouts/doc' | ||
import metadata from './metadata' | ||
/* @ts-expect-error toc */ | ||
import Content, { toc } from './content.mdx' | ||
import generate from 'internal/utils/generate-metadata' | ||
import { getUnitCategories } from '~/site/metadata' | ||
|
||
export const dynamic = 'force-static' | ||
export const revalidate = false | ||
|
||
export async function generateMetadata(props: any, parent: any) { | ||
return await generate(metadata, props, parent) | ||
} | ||
|
||
export default async function Page(props: any) { | ||
return ( | ||
<Layout {...props} $type="preview" pageCategories={getUnitCategories('components')} pageDirname={__dirname} metadata={metadata} toc={toc} > | ||
<Content /> | ||
</Layout > | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import Basic from '../../previews/tab-view/basic/content' | ||
|
||
## Basic | ||
<CodePreview src="tab-view/basic" raw={require('!!raw-loader!../../previews/tab-view/basic/content').default}> | ||
<Basic /> | ||
</CodePreview> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import define from 'internal/utils/metadata' | ||
|
||
const metadata = define({ | ||
title: 'Tab View', | ||
description: 'A tab view presents multiple mutually exclusive content panes in the same context area, which users can switch between.', | ||
category: 'View Organizing', | ||
openGraph: { | ||
images: new URL('~/site/public/images/components/select.jpg', import.meta.url).toString() | ||
}, | ||
filename: import.meta.url | ||
}) | ||
|
||
export default metadata |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import Layout from 'internal/layouts/doc' | ||
import metadata from './metadata' | ||
/* @ts-expect-error toc */ | ||
import Content, { toc } from './content.mdx' | ||
import generate from 'internal/utils/generate-metadata' | ||
import { getUnitCategories } from '~/site/metadata' | ||
|
||
export const dynamic = 'force-static' | ||
export const revalidate = false | ||
|
||
export async function generateMetadata(props: any, parent: any) { | ||
return await generate(metadata, props, parent) | ||
} | ||
|
||
export default async function Page(props: any) { | ||
return ( | ||
<Layout {...props} $type="preview" pageCategories={getUnitCategories('components')} pageDirname={__dirname} metadata={metadata} toc={toc} > | ||
<Content /> | ||
</Layout > | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { Segment, Segments } from '@master/ui.react' | ||
|
||
export default () => <> | ||
<Segments size='sm'> | ||
<Segment active>Grid</Segment> | ||
<Segment>List</Segment> | ||
</Segments> | ||
<Segments> | ||
<Segment active>Grid</Segment> | ||
<Segment>List</Segment> | ||
</Segments> | ||
<Segments size='lg'> | ||
<Segment active>Grid</Segment> | ||
<Segment>List</Segment> | ||
</Segments> | ||
</> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import Content from './content' | ||
|
||
export default function Page() { | ||
return ( | ||
<div className="app-demo gap:8x flex:col@<2xs bg:none!"> | ||
<Content /> | ||
</div> | ||
) | ||
} |
35 changes: 35 additions & 0 deletions
35
site/app/[locale]/previews/segments/with-leading-icon/content.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { Segment, Segments } from '@master/ui.react' | ||
import { IconLayoutGrid, IconList } from '@tabler/icons-react' | ||
|
||
export default () => <> | ||
<Segments size="sm"> | ||
<Segment active> | ||
<IconLayoutGrid className='segment-icon' /> | ||
Grid | ||
</Segment> | ||
<Segment> | ||
<IconList className='segment-icon' /> | ||
List | ||
</Segment> | ||
</Segments> | ||
<Segments> | ||
<Segment active> | ||
<IconLayoutGrid className='segment-icon' /> | ||
Grid | ||
</Segment> | ||
<Segment> | ||
<IconList className='segment-icon' /> | ||
List | ||
</Segment> | ||
</Segments> | ||
<Segments size="lg"> | ||
<Segment active> | ||
<IconLayoutGrid className='segment-icon' /> | ||
Grid | ||
</Segment> | ||
<Segment> | ||
<IconList className='segment-icon' /> | ||
List | ||
</Segment> | ||
</Segments> | ||
</> |
Oops, something went wrong.