-
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
1 parent
774262b
commit 6c9b33c
Showing
9 changed files
with
112 additions
and
37 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 |
---|---|---|
|
@@ -8,6 +8,7 @@ const preview: Preview = { | |
color: /(background|color)$/i, | ||
date: /Date$/, | ||
}, | ||
expanded: true, | ||
}, | ||
}, | ||
} | ||
|
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 +1,49 @@ | ||
[demo](https://bitterteasweetorange.github.io/mui-easy-cascader/?path=/story/easycascaderinput--defalut) | ||
|
||
mui-easy-cascader is a cascading selection component library based on [Material UI](https://mui.com/material-ui/). | ||
|
||
## Feature | ||
|
||
- flat data, connect by id | ||
- search | ||
- highlight keyword | ||
- keyboard event | ||
|
||
## Install | ||
|
||
``` | ||
npm install mui-easy-cascader | ||
``` | ||
|
||
## Usage | ||
|
||
```jsx | ||
<EasyCascaderInput<{ | ||
id:string, | ||
name:string, | ||
childrenId:string[] | ||
pathId:string | ||
}> | ||
data={[ | ||
{ | ||
id: "a", | ||
name: "a", | ||
childrenId: ["b"], | ||
}, | ||
{ | ||
id: "b", | ||
name: "b", | ||
childrenId: ["c"], | ||
pathId: ["a"] | ||
}, | ||
{ | ||
id: "c", | ||
name: "c", | ||
pathId: ["a","b"] | ||
}, | ||
]} | ||
getNodeLabel={(node) => node.name} | ||
value={value} | ||
onChange={onChange} | ||
/> | ||
``` |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 { Canvas, Meta } from '@storybook/blocks' | ||
import * as Stories from './index.stories' | ||
|
||
<Meta of={Stories} /> | ||
|
||
# CascaderInput | ||
|
||
|
||
<Canvas of={Stories.Default} /> | ||
<Canvas of={Stories.DisplayPath} /> | ||
<Canvas of={Stories.Adornment} /> | ||
|
||
|
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,41 +1,61 @@ | ||
import { Chip } from '@mui/material' | ||
import type { Meta } from '@storybook/react' | ||
import type { Meta, StoryObj } from '@storybook/react' | ||
import { useState } from 'react' | ||
import { EasyCascaderInput } from '.' | ||
import { EasyCascaderInput, EasyCascaderInputProps } from '.' | ||
import { MockObject, mockObjectNodes } from '../mock' | ||
|
||
const meta = { | ||
title: 'EasyCascaderInput', | ||
component: EasyCascaderInput, | ||
argTypes: { | ||
helperText: { | ||
type: 'string', | ||
}, | ||
value: { | ||
control: false, | ||
}, | ||
}, | ||
} satisfies Meta<typeof EasyCascaderInput> | ||
|
||
export default meta | ||
|
||
export const Defalut = () => { | ||
type Story = StoryObj<EasyCascaderInputProps<MockObject>> | ||
|
||
const Template = (args: EasyCascaderInputProps<MockObject>) => { | ||
const [value, onChange] = useState<MockObject | null>(mockObjectNodes[2]) | ||
|
||
return ( | ||
<EasyCascaderInput<MockObject> | ||
data={mockObjectNodes} | ||
getNodeLabel={(node) => node.name} | ||
endAdornment={(node) => node.age && <Chip label={node.age} />} | ||
label={'label'} | ||
{...args} | ||
value={value} | ||
onChange={onChange} | ||
/> | ||
) | ||
} | ||
|
||
export const DisplayPath = () => { | ||
const [value, onChange] = useState<MockObject | null>(mockObjectNodes[1]) | ||
export const Default: Story = { | ||
render: (args) => <Template {...args} />, | ||
args: { | ||
label: 'label', | ||
data: mockObjectNodes, | ||
getNodeLabel: (node) => node.name, | ||
}, | ||
} | ||
|
||
return ( | ||
<EasyCascaderInput<MockObject> | ||
data={mockObjectNodes} | ||
getNodeLabel={(node) => node.name} | ||
value={value} | ||
onChange={onChange} | ||
displayPath | ||
/> | ||
) | ||
export const DisplayPath: Story = { | ||
render: (args) => <Template {...args} />, | ||
args: { | ||
displayPath: true, | ||
data: mockObjectNodes, | ||
getNodeLabel: (node) => node.name, | ||
}, | ||
} | ||
export const Adornment: Story = { | ||
render: (args) => <Template {...args} />, | ||
args: { | ||
data: mockObjectNodes, | ||
getNodeLabel: (node) => node.name, | ||
endAdornment: (node) => node.age && <Chip label={node.age} />, | ||
startAdornment: (node) => node.age && <Chip label={node.age} />, | ||
}, | ||
} |
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,4 +1 @@ | ||
export * from './EasyCascaderInput' | ||
export * from './EasyHighlight' | ||
export * from './EasyPopper' | ||
export * from './types' |
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