# TiDB Cloud UIKit - Complete Documentation This file contains comprehensive documentation for the TiDB Cloud UIKit library including: - Complete component documentation with usage examples - Business components for common patterns - React hooks documentation - Icon library reference All code examples use production npm package imports: - @tidbcloud/uikit - Core components and hooks - @tidbcloud/uikit/biz - Business components - @tidbcloud/uikit/icons - Icon components ================================================================================ ## QUICK REFERENCE ### Import Examples ```tsx // Core components import { Button, TextInput, Select, Modal, Table } from '@tidbcloud/uikit'; // Business components import { Form, FormTextInput, ProTable, CodeBlock } from '@tidbcloud/uikit/biz'; // Hooks import { useDisclosure, useClipboard, useLocalStorage } from '@tidbcloud/uikit'; // Icons import { IconAlertCircle, IconCheck, IconX } from '@tidbcloud/uikit/icons'; ``` ## PRIMITIVE COMPONENTS Basic UI components from @tidbcloud/uikit Primary Package: @tidbcloud/uikit -------------------------------------------------------------------------------- ### Accordion Package: @tidbcloud/uikit Import: import { Accordion } from '@tidbcloud/uikit'; Description: Divide content into collapsible sections. Divide content into collapsible sections. ## Usage Accordion allows users to expand and collapse sections of content. It helps manage large amounts of information in a limited space by showing only the section headers initially and revealing content on interaction. ```tsx const data = [ { emoji: '🍎', value: 'Apples', description: 'Crisp and refreshing fruit. Apples are known for their versatility and nutritional benefits.' }, { emoji: '🍌', value: 'Bananas', description: 'Naturally sweet and potassium-rich fruit. Bananas are a popular choice for their energy-boosting properties.' }, { emoji: '🥦', value: 'Broccoli', description: 'Nutrient-packed green vegetable. Broccoli is packed with vitamins, minerals, and fiber.' } ] function Demo() { const items = data.map((item) => ( {item.value} {item.description} )) return {items} } ``` ## Multiple items open Set `multiple` prop to allow multiple items to be opened at the same time: ```tsx function Demo() { return ( First item First panel content Second item Second panel content ) } ``` ## Controlled ```tsx function Demo() { const [value, setValue] = useState(null) return ( Item 1 Panel 1 Item 2 Panel 2 ) } ``` ## Variants Accordion supports several variants: `default`, `contained`, `filled`, and `separated`. ```tsx function Demo() { return ( Item 1 Panel 1 ) } ``` ## Disabled items Set the `disabled` prop on `Accordion.Control` to disable it: ```tsx function Demo() { return ( Enabled item Content Disabled item Content ) } ``` ## Props | Prop | Type | Default | Description | | ---------------------- | ----------------------------------------------------- | ----------- | ----------------------------------------------------- | | chevron | `React.ReactNode` | - | Custom chevron icon | | chevronPosition | `'left' \| 'right'` | `'right'` | Position of the chevron relative to the item label | | chevronSize | `number \| string` | `24` | Size of the chevron icon container | | defaultValue | `string \| string[] \| null` | - | Uncontrolled component default value | | disableChevronRotation | `boolean` | - | If set, chevron rotation is disabled | | loop | `boolean` | `true` | If set, arrow keys loop through items | | multiple | `boolean` | - | If set, multiple items can be opened at the same time | | onChange | `(value) => void` | - | Called when value changes | | order | `2 \| 3 \| 4 \| 5 \| 6` | - | Heading order, has no effect on visuals | | radius | `MantineRadius` | - | Border radius | | transitionDuration | `number` | `200` | Transition duration in ms | | value | `string \| string[] \| null` | - | Controlled component value | | variant | `'default' \| 'contained' \| 'filled' \| 'separated'` | `'default'` | Visual variant | -------------------------------------------------------------------------------- ### ActionIcon Package: @tidbcloud/uikit Import: import { ActionIcon } from '@tidbcloud/uikit'; Description: Icon button component. Icon button component. ## Usage ```tsx function Demo() { return ( ) } ``` ## Variants ActionIcon supports several variants: `filled`, `light`, `outline`, `transparent`, `white`, `subtle`, `default`, and `gradient`. ```tsx function Demo() { return ( ) } ``` ## Gradient ```tsx function Demo() { return ( ) } ``` ## Size You can use any valid CSS value in `size` prop. When `size` is a number, the value is treated as `px` units. ```tsx function Demo() { return ( ) } ``` ## Loading state When `loading` prop is set, ActionIcon will be disabled and a Loader will be rendered in the center: ```tsx function Demo() { return ( ) } ``` ## Disabled state ```tsx function Demo() { return ( ) } ``` ## ActionIcon.Group ```tsx function Demo() { return ( ) } ``` ## Props | Prop | Type | Default | Description | | ----------- | ----------------------- | ---------- | ------------------------------------------------------------- | | children | `React.ReactNode` | - | Icon element | | color | `MantineColor` | - | Key of `theme.colors` or any valid CSS color | | disabled | `boolean` | - | Sets disabled attribute | | gradient | `MantineGradient` | - | Gradient values used with `variant="gradient"` | | loading | `boolean` | - | If set, Loader component is displayed instead of the children | | loaderProps | `LoaderProps` | - | Props passed to the Loader component | | radius | `MantineRadius` | - | Border radius | | size | `number \| MantineSize` | `'md'` | Controls width and height | | variant | `string` | `'filled'` | Visual variant | -------------------------------------------------------------------------------- ### Affix Package: @tidbcloud/uikit Import: import { Affix } from '@tidbcloud/uikit'; Description: Renders children inside portal at fixed position. Renders children inside portal at fixed position. ## Usage `Affix` renders a div element with a fixed position inside the Portal component. Use it to display elements fixed at any position on the screen, for example, scroll to top button: ```tsx function Demo() { const [scroll, scrollTo] = useWindowScroll() return ( <> 0}> {(transitionStyles) => ( )} ) } ``` ## Position Use `position` prop to control the position of the Affix: ```tsx function Demo() { return ( ) } ``` ## Props | Prop | Type | Default | Description | | ------------ | ------------------------------------------------------------------ | ------------------------- | ------------------------------------------------------------- | | children | `React.ReactNode` | - | Content to render inside Affix | | portalProps | `PortalProps` | - | Props passed to the Portal component | | position | `{ top?: number; right?: number; bottom?: number; left?: number }` | `{ bottom: 0, right: 0 }` | Affix position on screen | | withinPortal | `boolean` | `true` | Determines whether component should be rendered within Portal | | zIndex | `number` | - | Root element z-index property | -------------------------------------------------------------------------------- ### Alert Package: @tidbcloud/uikit Import: import { Alert } from '@tidbcloud/uikit'; Description: Attract user attention with important static message. Attract user attention with important static message. ## Usage ```tsx function Demo() { return ( } title="Alert title" color="blue"> Something important happened! You should check it out. ) } ``` ## Variants Alert supports several variants: `filled`, `light`, `outline`, `default`, and `transparent`. ```tsx function Demo() { return ( This is a filled alert This is a light alert This is an outline alert ) } ``` ## With close button Set `withCloseButton` prop to display a close button: ```tsx function Demo() { return ( } title="Dismissible alert" withCloseButton closeButtonLabel="Dismiss" onClose={() => console.log('Alert closed')} > Click the X button to dismiss this alert. ) } ``` ## Accessibility - Root element role is set to `alert` - `aria-describedby` is set to body element id, `aria-labelledby` is set to title element id if `title` is provided - Set `closeButtonLabel` prop to make close button accessible ```tsx // ✅ Accessible function Valid() { return } ``` ## Props | Prop | Type | Default | Description | | ---------------- | ----------------- | --------- | --------------------------------------------------- | | children | `React.ReactNode` | - | Alert body content | | closeButtonLabel | `string` | - | Close button aria-label | | color | `MantineColor` | - | Key of theme.colors or any valid CSS color | | icon | `React.ReactNode` | - | Icon displayed next to the title | | onClose | `() => void` | - | Called when the close button is clicked | | radius | `MantineRadius` | - | Border radius | | title | `React.ReactNode` | - | Alert title | | variant | `string` | `'light'` | Visual variant | | withCloseButton | `boolean` | `false` | Determines whether close button should be displayed | -------------------------------------------------------------------------------- ### AlphaSlider Package: @tidbcloud/uikit Import: import { AlphaSlider } from '@tidbcloud/uikit'; Description: Pick alpha (opacity) value for colors. Pick alpha (opacity) value for colors. ## Usage `AlphaSlider` is used to select the alpha (opacity) channel for colors. It is typically used alongside `ColorPicker` or `HueSlider`. ```tsx function Demo() { const [value, setValue] = useState(1) return ( <> Alpha value: {value} ) } ``` ## With color The `color` prop determines the color displayed in the gradient: ```tsx function Demo() { return ( ) } ``` ## Props | Prop | Type | Default | Description | | ----------- | ------------------------- | ------- | -------------------------------------------- | | color | `string` | - | Color displayed in the alpha slider gradient | | onChange | `(value: number) => void` | - | Called when value changes | | onChangeEnd | `(value: number) => void` | - | Called when user stops dragging | | size | `MantineSize` | `'md'` | Controls slider height | | value | `number` | - | Current alpha value (0-1) | -------------------------------------------------------------------------------- ### Anchor Package: @tidbcloud/uikit Import: import { Anchor } from '@tidbcloud/uikit'; Description: Display link with theme styles. Display link with theme styles. ## Usage ```tsx function Demo() { return ( Anchor component ) } ``` ## Underline Use `underline` prop to configure `text-decoration` property: - `always` - link is always underlined - `hover` - link is underlined on hover - `never` - link is never underlined - `not-hover` - link is underlined when not hovered ```tsx function Demo() { return ( Underline always Underline hover Underline never ) } ``` ## Text props `Anchor` supports all Text component props: ```tsx function Demo() { return ( A link with pink to yellow gradient ) } ``` ## Polymorphic component Anchor is a polymorphic component – its default root element is `a`, but it can be changed to any other element or component: ```tsx function Demo() { return ( Link with Next.js Link ) } ``` ## Props | Prop | Type | Default | Description | | --------- | ----------------------------------------------- | --------- | ---------------------------------------------------------- | | children | `React.ReactNode` | - | Link content | | gradient | `MantineGradient` | - | Gradient configuration for `variant="gradient"` | | href | `string` | - | Link URL | | size | `MantineSize` | - | Controls font-size and line-height | | target | `string` | - | Link target attribute | | underline | `'always' \| 'hover' \| 'never' \| 'not-hover'` | `'hover'` | Defines when text-decoration: underline styles are applied | -------------------------------------------------------------------------------- ### AnimatedNumber Package: @tidbcloud/uikit Import: import { AnimatedNumber } from '@tidbcloud/uikit'; Description: Animated number component with smooth transitions. Animated number component with smooth transitions. ## Usage `AnimatedNumber` displays numbers with smooth animations when values change. It's powered by [number-flow](https://number-flow.barvian.me/). ```tsx function Demo() { const [value, setValue] = useState(1234) return ( <> ) } ``` ## Formatting You can use standard NumberFlowProps to format the output: ```tsx function Demo() { return } ``` ## AnimatedNumber.Group If an `AnimatedNumber` affects another `AnimatedNumber`'s position, you can wrap them in an `AnimatedNumber.Group` to properly sync their transitions: ```tsx function Demo() { return ( / ) } ``` ## Style props `AnimatedNumber` supports all Box component style props: ```tsx function Demo() { return } ``` ## Props | Prop | Type | Default | Description | | ----------- | -------------------------- | ------- | ------------------------------------- | | value | `number` | - | The number to display | | format | `Intl.NumberFormatOptions` | - | Formatting options for the number | | locales | `string \| string[]` | - | Locale(s) for number formatting | | animated | `boolean` | `true` | Whether to animate value changes | | trend | `boolean` | - | Highlight positive/negative changes | | ...BoxProps | - | - | All Box component props are supported | -------------------------------------------------------------------------------- ### AppShell Package: @tidbcloud/uikit Import: import { AppShell } from '@tidbcloud/uikit'; Description: Responsive shell for your application with header, navbar, aside and footer. Responsive shell for your application with header, navbar, aside and footer. ## Usage `AppShell` is a layout component that can be used to implement a common Header / Navbar / Footer / Aside layout pattern. All `AppShell` components have `position: fixed` style. ```tsx function Demo() { const [opened, { toggle }] = useDisclosure() return (
Logo
Navbar Main content
) } ``` ## AppShell components - `AppShell` – root component that wraps all other sections - `AppShell.Header` – fixed header at the top - `AppShell.Navbar` – fixed navbar on the left - `AppShell.Aside` – fixed aside on the right - `AppShell.Footer` – fixed footer at the bottom - `AppShell.Main` – main content area - `AppShell.Section` – utility for grouping content inside Navbar or Aside ## Responsive navbar ```tsx function Demo() { const [opened, { toggle }] = useDisclosure() return ( Logo Main content ) } ``` ## With aside ```tsx function Demo() { return ( Header Navbar Main Aside ) } ``` ## Props | Prop | Type | Default | Description | | ------------------ | ----------------------------- | ----------- | --------------------------------------------------- | | aside | `AppShellAsideConfiguration` | - | Aside configuration | | disabled | `boolean` | - | If set, Navbar, Aside, Header and Footer are hidden | | footer | `AppShellFooterConfiguration` | - | Footer configuration | | header | `AppShellHeaderConfiguration` | - | Header configuration | | layout | `'default' \| 'alt'` | `'default'` | Layout arrangement | | navbar | `AppShellNavbarConfiguration` | - | Navbar configuration | | padding | `MantineSpacing` | - | Padding of the main section | | transitionDuration | `number` | - | Duration of transitions in ms | | withBorder | `boolean` | `true` | If set, components have a border | | zIndex | `number` | `100` | z-index of all elements | -------------------------------------------------------------------------------- ### AspectRatio Package: @tidbcloud/uikit Import: import { AspectRatio } from '@tidbcloud/uikit'; Description: Maintain responsive consistent width/height ratio. Maintain responsive consistent width/height ratio. ## Usage `AspectRatio` maintains a consistent width/height ratio. It can be used to display images, maps, videos and other media. ```tsx function Demo() { return ( Example ) } ``` ## Map embed ```tsx function Demo() { return (