>
);
};
```
--------------------------------
### Run Development Server
Source: https://github.com/kubesphere/kube-design/blob/master/docs/README.md
Use npm or yarn to start the development server for the Next.js project. Open http://localhost:3000 in your browser to view the application.
```bash
npm run dev
# or
yarn dev
```
--------------------------------
### Default Generated Configuration Example
Source: https://github.com/kubesphere/kube-design/blob/master/docs/docs/en/components/Table.mdx
An example of a default configuration generated by `getDefaultTableOptions`, including registration of handlers based on manual control.
```javascript
{
storageStateKeys: ['columnVisibility'],
registerHandlers: manual
? [
{
handlerName: 'onParamsChange',
stateKeys: ['pagination', 'columnFilters', 'sorting'],
},
]
: [],
}
```
--------------------------------
### Customizing Themes with KubedConfigProvider
Source: https://github.com/kubesphere/kube-design/blob/master/docs/docs/en/guide/KubedConfigProvider.mdx
Shows how to define and apply custom dark and light themes using themeUtils.createFromDark and themeUtils.createFromLight. The example includes a button to toggle between the custom themes.
```jsx
import { KubedConfigProvider, Button, themeUtils } from "@kubed/components"
function App() {
const customDarkTheme = themeUtils.createFromDark({
type: "customDark",
palette: {
accents_1: "#1098AD",
accents_2: "#3BC9DB",
},
})
const customLightTheme = themeUtils.createFromLight({
type: "customLight",
palette: {
accents_1: "#F76707",
accents_2: "#FFA94D",
},
})
const [themeType, setThemeType] = useState("customDark")
return (
)
}
```
--------------------------------
### Basic KubedConfigProvider Usage
Source: https://github.com/kubesphere/kube-design/blob/master/docs/docs/en/guide/KubedConfigProvider.mdx
Demonstrates the basic setup of KubedConfigProvider at the application root. Import the component and wrap your main App component with it, specifying theme type and locale.
```jsx
import { KubedConfigProvider } from "@kubed/components";
;
```
--------------------------------
### Applying a Custom Dark Theme
Source: https://github.com/kubesphere/kube-design/blob/master/docs/docs/en/guide/ThemeObject.mdx
Demonstrates how to create and apply a custom dark theme using `themeUtils.createFromDark` within `KubedConfigProvider`. This example customizes the theme's palette, layout input sizes, and button shadow.
```jsx
import { KubedConfigProvider, Button, themeUtils } from "@kubed/components"
function App() {
const customDarkTheme = themeUtils.createFromDark({
type: "customDark",
palette: {
colors: {
green: ["#E9EDFC", "#E9EDFC", "#E9EDFC", "#E9EDFC", "#E9EDFC"],
},
},
layout: {
inputSizes: {
sm: "24px",
},
},
expressiveness: {
buttonShadow: () => "10px 10px 10px hotpink",
},
})
return (
)
}
```
--------------------------------
### useToggle Hook Example
Source: https://github.com/kubesphere/kube-design/blob/master/docs/docs/en/hooks/useToggle.mdx
Demonstrates how to use the useToggle hook to switch between 'light' and 'dark' themes. It shows how to toggle to the next value, or set it to a specific value.
```jsx
import { useToggle } from '@kubed/hooks';
import { Button } from '@kubed/components'
export default function App() {
const [value, toggle] = useToggle('light', ['light', 'dark']);
return (
themeType: {`${value}`}
);
}
```
--------------------------------
### Imperative Modal Example
Source: https://github.com/kubesphere/kube-design/blob/master/docs/docs/en/components/Modal.mdx
Shows how to open a modal imperatively using the `useModal` hook. This is useful for complex interactions or nested modals.
```javascript
() => {
const modal = useModal();
const openChildModal = () => {
modal.open({
title: 'Imperative Modal',
description: 'description text',
content: 'modal content',
});
};
const content = ;
const openModal = () => {
modal.open({
title: 'Imperative Modal',
description: 'description text',
content,
});
};
return ;
}
```
--------------------------------
### Column Offset Example
Source: https://github.com/kubesphere/kube-design/blob/master/docs/docs/en/components/Grid.mdx
Shows how to use the 'offset' prop on Col components to create space or indentation from the left side of the grid.
```javascript
() => {
const PlaceHolder = ({ children }) => (
)
}
```
--------------------------------
### Update Notification Example
Source: https://github.com/kubesphere/kube-design/blob/master/docs/docs/en/components/Notify.mdx
Illustrates how to update an existing notification. A loading notification is initially displayed, and then updated to a success message using its `id`.
```javascript
() => {
let notifyId;
const trigger = () => {
notifyId = notify.loading('uploading...');
};
const update = () => {
notify.success('upload success !', { id: notifyId });
};
return (
);
}
```
--------------------------------
### Customizable Grid Columns
Source: https://github.com/kubesphere/kube-design/blob/master/docs/docs/en/components/Grid.mdx
Demonstrates how to customize the total number of grids in a Row by setting the 'columns' prop. This example sets the grid system to 24 columns.
```javascript
() => {
const PlaceHolder = ({ children }) => (
{children}
);
return (
col-12
col-6
col-6
)
}
```
--------------------------------
### BaseTable Column Fixed Example
Source: https://github.com/kubesphere/kube-design/blob/master/docs/docs/en/components/Table.mdx
Demonstrates how to create a table with fixed left and right columns, as well as a sticky header. This is useful for tables with many columns where key information needs to remain visible.
```jsx
import { BaseTable } from '@kubed/components';
import * as React from 'react';
() => {
const { Table, TableHead, TableBody, TableRow, TableCell } = BaseTable;
const data = React.useMemo(() => {
return [...Array(100)].fill(1).map((_, i) => ({
col1: i,
col2: `col2-${i}`,
col3: `col3-${i}`,
}));
}, []);
return (
);
};
```
--------------------------------
### Search Box Input
Source: https://github.com/kubesphere/kube-design/blob/master/docs/docs/en/components/Input.mdx
An example of creating a search box by combining a standard input with a search button, utilizing icons for prefix and suffix.
```javascript
() => {
const { Magnifier, Appcenter } = KubeIcon;
return (
} suffix={} />
} />
)
}
```
--------------------------------
### Tabs with Grow Behavior
Source: https://github.com/kubesphere/kube-design/blob/master/docs/docs/en/components/Tabs.mdx
Shows how to make the Tabs component take up available horizontal space using the 'grow' prop. This example uses the 'line' variant.
```javascript
() => (
one
Two
Three
)
```
--------------------------------
### useBooleanToggle Hook Example
Source: https://github.com/kubesphere/kube-design/blob/master/docs/docs/en/hooks/useToggle.mdx
Illustrates the use of the useBooleanToggle hook for toggling between true and false. It includes functions to toggle, set to false, and set to true.
```jsx
import { useBooleanToggle } from '@kubed/hooks';
import { Button } from '@kubed/components'
export default function App() {
const [value, toggle] = useBooleanToggle();
return (
state:{`${value}`}
);
}
```
--------------------------------
### Radio Group Example
Source: https://github.com/kubesphere/kube-design/blob/master/docs/docs/en/components/Radio.mdx
Illustrates how to group multiple Radio components using `RadioGroup`. The `onChange` handler is triggered when a new radio button is selected within the group.
```javascript
() => {
const onChange = (val) => {
console.log(val);
};
return (
<>
>
);
}
```
--------------------------------
### Customizing Theme Palette Colors
Source: https://github.com/kubesphere/kube-design/blob/master/docs/docs/en/guide/ThemeObject.mdx
Shows how to customize the primary color of a theme by overriding the `palette.colors.green` property. This example uses `themeUtils.createFromDark` to define a custom theme with a specific green color scale.
```jsx
() => {
const customDarkTheme = themeUtils.createFromDark({
type: "customDark",
palette: {
colors: {
green: ["#E3FAFC", "#C5F6FA", "#99E9F2", "#66D9E8", "#3BC9DB"],
},
// primary: "#3BC9DB",
}
});
return ;
};
```
--------------------------------
### Basic AutoComplete Usage
Source: https://github.com/kubesphere/kube-design/blob/master/docs/docs/en/components/AutoComplete.mdx
Demonstrates how to set up a basic AutoComplete component. It requires setting the `options` property for data and handling search events with `onSearch`. The `value`, `onSelect`, and `onChange` props are also shown.
```javascript
() => {
const [value, setValue] = React.useState('');
const [options, setOptions] = React.useState([]);
const mockVal = (str, repeat = 1) => ({
value: str.repeat(repeat),
});
const onSearch = (searchText) => {
setOptions(
!searchText ? [] : [mockVal(searchText), mockVal(searchText, 2), mockVal(searchText, 3)]
);
};
const onSelect = (data) => {
console.log('onSelect', data);
};
const onChange = (data) => {
setValue(data);
};
return (
)
}
```
--------------------------------
### Custom Selection Rendering
Source: https://github.com/kubesphere/kube-design/blob/master/docs/docs/en/components/Select.mdx
Customize how selected options are rendered in the select box by specifying the `optionLabelProp`. This example shows rendering country flags and names.
```javascript
() => {
function handleChange(value){
console.log(`selected ${value}`);
}
return (
)
}
```
--------------------------------
### Long Notification Example
Source: https://github.com/kubesphere/kube-design/blob/master/docs/docs/en/components/Notify.mdx
Shows how to display a long notification message. The `notify.success` function is used with a lengthy string to demonstrate truncation or wrapping behavior.
```javascript
() => {
const trigger = () =>
notify.success(
'Here is your toast.Here is your toast.Here is your toast.Here is your toast.Here is your toast.Here is your toast.Here is your toast.'
);
return (
);
}
```
--------------------------------
### Initialize Application with KubedConfigProvider
Source: https://github.com/kubesphere/kube-design/blob/master/README.md
Wrap your React application with KubedConfigProvider and include CssBaseline for style normalization.
```jsx
import { CssBaseline, KubedConfigProvider } from '@kubed/components';
const Application = () => (
// ---> Normalize styles
// ---> Root of your application
)
```
--------------------------------
### Styled Popover
Source: https://github.com/kubesphere/kube-design/blob/master/docs/docs/en/components/Popover.mdx
Shows how to style a Popover component with custom title, content, width, and maxWidth. This example uses a button with an extra-large radius as the trigger.
```javascript
() => (
)
```
--------------------------------
### Input with Prefix and Suffix
Source: https://github.com/kubesphere/kube-design/blob/master/docs/docs/en/components/Input.mdx
Shows how to use the `addonBefore` and `addonAfter` props to add content before and after the input field, as well as using `prefix` and `suffix` for icons.
```javascript
() => {
const { Appcenter } = KubeIcon;
return (
} />
)
}
```
--------------------------------
### Basic Input Usage
Source: https://github.com/kubesphere/kube-design/blob/master/docs/docs/en/components/Input.mdx
Demonstrates the basic usage of the Input component with a placeholder and a specified width.
```javascript
```
--------------------------------
### Basic Select Usage
Source: https://github.com/kubesphere/kube-design/blob/master/docs/docs/en/components/Select.mdx
Demonstrates the basic usage of the Select component, including setting placeholders, default values, disabled states, loading indicators, and clearable options.
```javascript
() => {
const { Option } = Select;
return (
<>
>
)
}
```
--------------------------------
### Basic Menu Usage
Source: https://github.com/kubesphere/kube-design/blob/master/docs/docs/en/components/Menu.mdx
Demonstrates how to use the Menu component with nested MenuItem components. Includes icons and click callbacks for interactive elements.
```javascript
() => {
const { Add, Stop, Pen, Trash } = KubeIcon;
const clickCallback = () => {
console.log('you click me')
}
return (
)
}
```
--------------------------------
### Basic Dropdown with Menu
Source: https://github.com/kubesphere/kube-design/blob/master/docs/docs/en/components/Dropdown.mdx
Demonstrates a basic dropdown with a menu containing various actions. The default trigger is click. Ensure KubeIcon and Button components are available.
```javascript
() => {
const { Add, Stop, Pen, Trash, More } = KubeIcon;
const MenuComponent = (
);
return (
)
}
```
--------------------------------
### Basic Badge Usage
Source: https://github.com/kubesphere/kube-design/blob/master/docs/docs/en/components/Badge.mdx
Demonstrates the simplest way to use the Badge component with text or numbers.
```javascript
() => (
KubeSphere12
)
```
--------------------------------
### InputNumber Basic Usage
Source: https://github.com/kubesphere/kube-design/blob/master/docs/docs/en/components/InputNumber.mdx
Demonstrates the basic usage of the InputNumber component with minimum, maximum, and step value configurations.
```javascript
```
--------------------------------
### Loading Component Basic Usage
Source: https://github.com/kubesphere/kube-design/blob/master/docs/docs/en/components/Loading.mdx
Demonstrates the basic usage of the Loading component with different sizes (small, medium, large).
```javascript
() => (
)
```
--------------------------------
### useDidUpdate Hook Example
Source: https://github.com/kubesphere/kube-design/blob/master/docs/docs/en/hooks/useDidUpdate.mdx
Demonstrates how to use the useDidUpdate hook to perform an action only after the component has updated based on dependency changes. It initializes a counter and an update counter, and increments the update counter each time the main counter changes.
```jsx
import React from 'react';
import { useDidUpdate } from '@kubed/hooks';
import { Button, Group } from '@kubed/components'
export default function App() {
const [counter, setCounter] = React.useState(0);
const [updateCount, setUpdateCount] = React.useState(0);
useDidUpdate(() => {
setUpdateCount((updateCount) => updateCount + 1)
}, [counter]);
return (
counter:{counter}
updateCount: {updateCount}
);
}
```
--------------------------------
### Basic Container
Source: https://github.com/kubesphere/kube-design/blob/master/docs/docs/en/components/Container.mdx
Demonstrates the basic usage of the Container component. Use this for simple content wrapping with a background.
```javascript
```
--------------------------------
### Basic Modal Usage
Source: https://github.com/kubesphere/kube-design/blob/master/docs/docs/en/components/Modal.mdx
Demonstrates how to open and close a basic modal dialog. Use this when requiring user interaction or feedback.
```javascript
() => {
const [visible, setVisible] = React.useState(false);
const { Cluster } = KubeIcon;
const ref = React.createRef();
const openModal = () => {
setVisible(true);
};
const closeModal = () => {
console.log(ref.current);
setVisible(false);
};
return (
<>
}
onCancel={closeModal}
>
Modal content
>
);
}
```
--------------------------------
### Basic Switch
Source: https://github.com/kubesphere/kube-design/blob/master/docs/docs/en/components/Switch.mdx
Demonstrates the basic usage of the Switch component with a label.
```javascript
() =>
```
--------------------------------
### Container Size and Padding
Source: https://github.com/kubesphere/kube-design/blob/master/docs/docs/en/components/Container.mdx
Shows how to apply different sizes and padding to the Container component. Use 'size' and 'padding' props for responsive layouts.
```javascript
<>
container
container
>
```
--------------------------------
### Basic Grid Layout
Source: https://github.com/kubesphere/kube-design/blob/master/docs/docs/en/components/Grid.mdx
Demonstrates the fundamental usage of Row and Col components to create a basic grid layout with columns of equal width.
```javascript
() => {
const PlaceHolder = ({ children }) => (
;
};
```
--------------------------------
### Basic Tooltip Usage
Source: https://github.com/kubesphere/kube-design/blob/master/docs/docs/en/components/Tooltip.mdx
Demonstrates the fundamental usage of the Tooltip component to display a simple text popup on mouse enter.
```javascript
() => (
)
```
--------------------------------
### Basic Tabs Usage
Source: https://github.com/kubesphere/kube-design/blob/master/docs/docs/en/components/Tabs.mdx
Demonstrates the fundamental implementation of the Tabs component with multiple Tab items.
```javascript
() => (
one
Two
Three
)
```
--------------------------------
### Basic Tag Usage
Source: https://github.com/kubesphere/kube-design/blob/master/docs/docs/en/components/Tag.mdx
Demonstrates the fundamental usage of the Tag component. Use this for simple text labels.
```javascript
() => (
KubeSphereKubeSphere
)
```
--------------------------------
### Basic Form Usage
Source: https://github.com/kubesphere/kube-design/blob/master/docs/docs/en/components/Form.mdx
Demonstrates a simple form with input fields for username, UID, and group. Includes validation rules and help text. Use for standard data entry forms.
```javascript
() => {
const onFinish = (values) => {
console.log(values);
};
return (
);
};
```
--------------------------------
### Customizing Theme Layout Input Sizes
Source: https://github.com/kubesphere/kube-design/blob/master/docs/docs/en/guide/ThemeObject.mdx
Demonstrates how to customize the input sizes for different breakpoints (xs, sm, md, lg, xl) within a theme. This allows for consistent sizing of input elements across various screen sizes.
```jsx
() => {
const customDarkTheme = themeUtils.createFromDark({
type: "customDark",
layout: {
inputSizes: {
xs:'16px',
sm: "24px",
md: "32px",
lg: "40px",
xl: "48px",
},
},
});
return ;
};
```
--------------------------------
### Tooltip in Control Mode
Source: https://github.com/kubesphere/kube-design/blob/master/docs/docs/en/components/Tooltip.mdx
Demonstrates how to control the visibility of the tooltip programmatically using state.
```javascript
() => {
const [visible, setVisible] = React.useState(true);
const show = () => setVisible(true);
const hide = () => setVisible(false);
return (
)
}
```
--------------------------------
### Imperative Confirm Modal
Source: https://github.com/kubesphere/kube-design/blob/master/docs/docs/en/components/Modal.mdx
Demonstrates how to open a confirmation modal imperatively using `useModal.confirm`. Use this for actions that require user confirmation.
```javascript
() => {
const modal = useModal();
return (
);
}
```
--------------------------------
### Basic Usage of useClipboard Hook
Source: https://github.com/kubesphere/kube-design/blob/master/docs/docs/en/hooks/useClipboard.mdx
Demonstrates how to use the useClipboard hook to copy a message and reset the clipboard state. It displays the copied status and any errors encountered.
```jsx
import { useClipboard } from '@kubed/hooks';
import { Button, Group } from '@kubed/components'
export default function App() {
const {copy, reset, error, copied } = useClipboard();
return (
{"copied: "+copied}
error: {error}
);
}
```
--------------------------------
### Tooltip Placement Options
Source: https://github.com/kubesphere/kube-design/blob/master/docs/docs/en/components/Tooltip.mdx
Illustrates various placement options for the Tooltip, including 'top', 'right', 'left', 'bottom', and their aligned variants.
```javascript
() => (
<>