-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: neil <msg@nancode.cn>
- Loading branch information
Showing
11 changed files
with
428 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import type { Meta, StoryObj } from '@storybook/react'; | ||
|
||
import { Input } from '@oss-compass/ui'; | ||
|
||
const meta: Meta<typeof Input> = { | ||
title: 'basic/Input', | ||
component: Input, | ||
argTypes: { | ||
disabled: { | ||
control: 'boolean', | ||
}, | ||
error: { | ||
control: 'boolean', | ||
}, | ||
placeholder: { | ||
control: 'string', | ||
}, | ||
}, | ||
}; | ||
|
||
export default meta; | ||
|
||
type Story = StoryObj<typeof Input>; | ||
|
||
export const Default: Story = { | ||
args: { disabled: false, error: false, placeholder: 'please input' }, | ||
render: (args) => { | ||
return <Input intent={'primary'} style={{ width: '400px' }} {...args} />; | ||
}, | ||
}; | ||
|
||
export const Secondary: Story = { | ||
args: { disabled: false, error: false, placeholder: 'please input' }, | ||
render: (args) => { | ||
return <Input intent={'secondary'} style={{ width: '400px' }} {...args} />; | ||
}, | ||
}; | ||
|
||
export const Md: Story = { | ||
args: { disabled: false, error: false, placeholder: 'please input' }, | ||
render: (args) => { | ||
return <Input size="md" style={{ width: '400px' }} {...args} />; | ||
}, | ||
}; | ||
|
||
export const Lg: Story = { | ||
args: { disabled: false, error: false, placeholder: 'please input' }, | ||
render: (args) => { | ||
return <Input size="lg" {...args} />; | ||
}, | ||
}; |
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,67 @@ | ||
import type { Meta, StoryObj } from '@storybook/react'; | ||
|
||
import RadioGroup from '@mui/material/RadioGroup'; | ||
import FormControlLabel from '@mui/material/FormControlLabel'; | ||
import FormControl from '@mui/material/FormControl'; | ||
import FormLabel from '@mui/material/FormLabel'; | ||
|
||
import { CustomRadio } from '@oss-compass/ui'; | ||
|
||
const meta: Meta<typeof RadioGroup> = { | ||
title: 'basic/RadioGroup', | ||
component: RadioGroup, | ||
argTypes: { | ||
defaultValue: { | ||
options: ['female', 'male', 'other'], | ||
control: { type: 'radio' }, | ||
}, | ||
value: { | ||
options: ['female', 'male', 'other'], | ||
control: { type: 'radio' }, | ||
}, | ||
}, | ||
}; | ||
|
||
export default meta; | ||
|
||
type Story = StoryObj<typeof RadioGroup>; | ||
|
||
export const CustomStyledRadio: Story = { | ||
args: { defaultValue: 'first' }, | ||
render: (args) => { | ||
const { defaultValue, value } = args; | ||
return ( | ||
<FormControl> | ||
<FormLabel id="demo-customized-radios">Gender</FormLabel> | ||
<RadioGroup | ||
defaultValue={defaultValue} | ||
value={value} | ||
aria-labelledby="demo-customized-radios" | ||
name="customized-radios" | ||
> | ||
<FormControlLabel | ||
value="female" | ||
control={<CustomRadio />} | ||
label="Female" | ||
/> | ||
<FormControlLabel | ||
value="male" | ||
control={<CustomRadio />} | ||
label="Male" | ||
/> | ||
<FormControlLabel | ||
value="other" | ||
control={<CustomRadio />} | ||
label="Other" | ||
/> | ||
<FormControlLabel | ||
value="disabled" | ||
disabled | ||
control={<CustomRadio />} | ||
label="(Disabled option)" | ||
/> | ||
</RadioGroup> | ||
</FormControl> | ||
); | ||
}, | ||
}; |
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,26 @@ | ||
import type { Meta, StoryObj } from '@storybook/react'; | ||
|
||
import { Select, SelectOption } from '@oss-compass/ui'; | ||
|
||
const meta: Meta<typeof Select> = { | ||
title: 'basic/Select', | ||
component: Select, | ||
argTypes: {}, | ||
}; | ||
|
||
export default meta; | ||
type Story = StoryObj<typeof Select>; | ||
|
||
export const Default: Story = { | ||
args: {}, | ||
render: (args) => { | ||
return ( | ||
<Select> | ||
<SelectOption value={'1'}>Frodo</SelectOption> | ||
<SelectOption value={'2'}>Sam</SelectOption> | ||
<SelectOption value={'3'}>Merry</SelectOption> | ||
<SelectOption value={'4'}>Pippin</SelectOption> | ||
</Select> | ||
); | ||
}, | ||
}; |
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,82 @@ | ||
import React, { forwardRef, FocusEvent, ChangeEvent } from 'react'; | ||
import classnames from 'classnames'; | ||
import { cva, type VariantProps } from 'class-variance-authority'; | ||
import { twMerge } from 'tailwind-merge'; | ||
import { useControllableValue } from 'ahooks'; | ||
|
||
interface InputProps { | ||
defaultValue?: string; | ||
name?: string; | ||
value?: string; | ||
style?: React.CSSProperties; | ||
onChange?: (value: string) => void; | ||
onBlur?: (e: FocusEvent<HTMLInputElement>) => void; | ||
className?: string; | ||
placeholder?: string; | ||
error?: boolean; | ||
disabled?: boolean; | ||
} | ||
|
||
const inputVariants = cva(' w-full text-base outline-none', { | ||
variants: { | ||
intent: { | ||
primary: 'border-solid border-black', | ||
secondary: 'border-solid border-[#CCCCCC]', | ||
}, | ||
size: { | ||
lg: 'h-12 px-3 border-2', | ||
md: 'h-10 px-3 border', | ||
}, | ||
}, | ||
defaultVariants: { | ||
intent: 'primary', | ||
size: 'md', | ||
}, | ||
}); | ||
|
||
interface InputVariants extends VariantProps<typeof inputVariants> {} | ||
|
||
export const Input = forwardRef<HTMLInputElement, InputProps & InputVariants>( | ||
(props, ref) => { | ||
const { | ||
intent, | ||
size, | ||
name, | ||
className, | ||
style, | ||
onBlur, | ||
placeholder, | ||
disabled = false, | ||
error = false, | ||
} = props; | ||
|
||
const [state, setState] = useControllableValue<string>(props, { | ||
defaultValuePropName: 'defaultValue', | ||
valuePropName: 'value', | ||
trigger: 'onChange', | ||
}); | ||
|
||
const cls = classnames( | ||
inputVariants({ intent, size }), | ||
[error ? 'border-red-500' : ''], | ||
className | ||
); | ||
|
||
return ( | ||
<input | ||
ref={ref} | ||
name={name} | ||
type="text" | ||
value={state} | ||
style={style} | ||
onChange={(e) => setState(e.target.value)} | ||
onBlur={(e) => onBlur?.(e)} | ||
placeholder={placeholder} | ||
disabled={disabled} | ||
className={twMerge(cls)} | ||
/> | ||
); | ||
} | ||
); | ||
|
||
Input.displayName = 'Input'; |
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 @@ | ||
import { styled } from '@mui/material/styles'; | ||
import Radio, { RadioProps } from '@mui/material/Radio'; | ||
|
||
export function CustomRadio(props: RadioProps) { | ||
return ( | ||
<Radio | ||
disableRipple | ||
sx={{ | ||
color: '#868690', | ||
'&.Mui-checked': { | ||
color: '#3A5BEF', | ||
}, | ||
}} | ||
{...props} | ||
/> | ||
); | ||
} |
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,45 @@ | ||
import * as React from 'react'; | ||
import { twMerge } from 'tailwind-merge'; | ||
import BaseOption, { OptionProps, OptionOwnerState } from '@mui/base/Option'; | ||
// import useIsDarkMode from '../shared/useIsDarkMode'; | ||
|
||
const getOptionColorClasses = ({ | ||
selected, | ||
highlighted, | ||
disabled, | ||
}: Partial<OptionOwnerState<number>>) => { | ||
let classes = ''; | ||
if (disabled) { | ||
classes += 'text-slate-400 '; | ||
} else { | ||
if (selected) { | ||
classes += '!bg-primary !text-white '; | ||
} else if (highlighted) { | ||
classes += 'bg-slate-100 text-slate-900 '; | ||
} | ||
classes += 'hover:bg-slate-100 hover:text-slate-900'; | ||
} | ||
return classes; | ||
}; | ||
|
||
export const SelectOption = React.forwardRef<HTMLLIElement, OptionProps<any>>( | ||
(props, ref) => { | ||
return ( | ||
<BaseOption | ||
ref={ref} | ||
{...props} | ||
slotProps={{ | ||
root: ({ selected, highlighted, disabled }) => ({ | ||
className: twMerge( | ||
`list-none p-2 mb-1 cursor-pointer last-of-type:border-b-0 ${getOptionColorClasses( | ||
{ selected, highlighted, disabled } | ||
)}` | ||
), | ||
}), | ||
}} | ||
/> | ||
); | ||
} | ||
); | ||
|
||
SelectOption.displayName = 'SelectOption'; |
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,43 @@ | ||
import React, { PropsWithChildren, forwardRef } from 'react'; | ||
import SelectBase, { SelectProps, SelectSlots } from '@mui/base/Select'; | ||
import useIsDarkMode from '../shared/useIsDarkMode'; | ||
|
||
export const Select = forwardRef(function Select< | ||
OptionValue, | ||
Multiple extends boolean | ||
>( | ||
props: SelectProps<OptionValue, Multiple>, | ||
ref: React.ForwardedRef<HTMLButtonElement> | ||
) { | ||
const { children } = props; | ||
const isDarkMode = useIsDarkMode(); | ||
|
||
return ( | ||
<div className={isDarkMode ? 'dark' : ''}> | ||
<SelectBase | ||
ref={ref} | ||
slotProps={{ | ||
root: ({ focusVisible, open }) => ({ | ||
className: `text-sm box-border w-80 px-3 py-2 text-left bg-white border border-solid border-[#ccc] text-slate-900 transition-all hover:bg-slate-50 outline-0 ${ | ||
focusVisible ? 'border-[#ccc] shadow-outline-purple' : '' | ||
} ${ | ||
open ? 'after:content-["▴"]' : 'after:content-["▾"]' | ||
} after:float-right`, | ||
}), | ||
listbox: { | ||
className: `text-sm p-1.5 my-1.5 w-80 overflow-auto outline-0 bg-white border border-solid border-slate-200 text-slate-900 shadow shadow-slate-200 `, | ||
}, | ||
popper: { className: `${isDarkMode ? 'dark' : ''} z-10` }, | ||
}} | ||
{...props} | ||
> | ||
{children} | ||
</SelectBase> | ||
</div> | ||
); | ||
}) as <OptionValue, Multiple extends boolean>( | ||
props: SelectProps<OptionValue, Multiple> & | ||
React.RefAttributes<HTMLUListElement> | ||
) => JSX.Element; | ||
|
||
export * from './Options'; |
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,7 @@ | ||
import { useTheme } from '@mui/system'; | ||
|
||
export default function useIsDarkMode() { | ||
// todo | ||
const theme = useTheme(); | ||
return theme.palette.mode === 'dark'; | ||
} |
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,4 @@ | ||
export * from './components/Button'; | ||
export * from './components/Input'; | ||
export * from './components/Redio'; | ||
export * from './components/Select'; |
Oops, something went wrong.
acc9117
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
storybook – ./
storybook-compass-team.vercel.app
storybook-git-main-compass-team.vercel.app
compass-web-2l68.vercel.app
acc9117
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
compass-web – ./
compass-web-compass-team.vercel.app
compass-web-preview.vercel.app
compass-web-git-main-compass-team.vercel.app