-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(list-picker): add list-picker (#1461)
- Loading branch information
1 parent
1e8458a
commit c5bc076
Showing
42 changed files
with
1,181 additions
and
323 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
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,15 +1,10 @@ | ||
import { isEmpty } from 'lodash'; | ||
import React from 'react'; | ||
import Input from '../input'; | ||
import { TriggerProps } from './interfance'; | ||
|
||
const Trigger: React.FC<TriggerProps> = (props) => { | ||
const { value, placeholder, getOptionByValue, separator, ...rest } = props; | ||
const name = value | ||
?.split('.') | ||
?.map((val) => getOptionByValue?.(val)?.label) | ||
?.join(separator); | ||
return <Input.Button placeholder={placeholder} value={isEmpty(value) ? undefined : name?.toString()} {...rest} />; | ||
const { value, placeholder, ...rest } = props; | ||
return <Input.Button placeholder={placeholder} value={value} {...rest} />; | ||
}; | ||
|
||
export default Trigger; |
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 |
---|---|---|
@@ -1,37 +1,31 @@ | ||
import { InputButtonProps } from '../input'; | ||
import { BaseItemProps, ListProps } from '../list/interfance'; | ||
import { ListProps, OptionProps as ListOptionProps } from '../list/interfance'; | ||
import { Placement } from '../popover/interface'; | ||
|
||
export interface CascaderProps extends Omit<ListProps, 'options' | 'onChange' | 'value'> { | ||
value?: string; | ||
defaultValue?: string; | ||
options: CascaderItemProps[]; | ||
options: OptionProps[]; | ||
size?: 'small' | 'normal'; | ||
/** | ||
多级文本的连接字符 | ||
*/ | ||
separator?: string; | ||
|
||
visible?: boolean; | ||
onVisibleChange?: (visible: boolean) => void; | ||
prefixCls?: string; | ||
triggerProps: Omit<TriggerProps, 'prefixCls' | 'onInputChange' | 'disabled' | 'getOptionByValue' | 'separator'>; | ||
onChange?: (value?: string) => void; | ||
onChange?: (val?: string | string[], options?: OptionProps | OptionProps[]) => void; | ||
getContainer?: (node: HTMLElement) => HTMLElement; | ||
overlayStyle?: React.CSSProperties; | ||
placement?: Placement; | ||
} | ||
|
||
export interface TriggerProps extends Omit<InputButtonProps, 'value' | 'active'> { | ||
value?: string; | ||
separator?: string; | ||
getOptionByValue: (optValue?: string) => CascaderItemProps | undefined; | ||
} | ||
|
||
export interface CascaderItemProps extends BaseItemProps { | ||
export interface OptionProps extends ListOptionProps { | ||
label: string; | ||
value: string; | ||
selectValue?: string; | ||
selectedParent?: string[]; | ||
onChange?: (value: string) => void; | ||
childrens?: CascaderItemProps[]; | ||
childrens?: OptionProps[]; | ||
} | ||
export interface TriggerProps extends Omit<InputButtonProps, 'value' | 'active'> { | ||
value?: string; | ||
} |
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 { OptionProps } from '../list/interfance'; | ||
|
||
export const getLabelByValue = (val?: string | string[], opts?: OptionProps | OptionProps[], separator = '') => | ||
val?.includes('.') | ||
? (val as any) | ||
?.split('.') | ||
?.reduce( | ||
(prev: string[], curr: string) => [...prev, (opts as OptionProps[]).find((o) => o.value === curr)?.label], | ||
[] | ||
) | ||
?.join(separator) | ||
: (opts as OptionProps).label; | ||
|
||
export default { | ||
getLabelByValue, | ||
}; |
This file was deleted.
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
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,30 @@ | ||
import React from 'react'; | ||
import List, { OptionProps } from '../list'; | ||
import { SelectionProps, StaticListPickerProps } from './interfance'; | ||
|
||
const StaticListPicker: React.FC<StaticListPickerProps & { needConfim?: boolean }> = (props) => { | ||
const { children, model, isSelection, options, ...rest } = props; | ||
// children has filter options, custom filter model such as :search | select | tab | other | ||
return ( | ||
<> | ||
{children} | ||
{isSelection ? ( | ||
<List.Selection> | ||
{(options as SelectionProps[]).map((option: SelectionProps) => ( | ||
<List | ||
{...rest} | ||
id={option.selectionValue} | ||
title={option.selectionTitle} | ||
options={option.options} | ||
model={model} | ||
/> | ||
))} | ||
</List.Selection> | ||
) : ( | ||
<List {...rest} options={options as OptionProps[]} model={model} /> | ||
)} | ||
</> | ||
); | ||
}; | ||
|
||
export default StaticListPicker; |
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 React from 'react'; | ||
import Input from '../input'; | ||
import { TriggerProps } from './interfance'; | ||
|
||
const Trigger: React.FC<TriggerProps> = (props) => { | ||
const { value, placeholder, onClear, ...rest } = props; | ||
const handleClear = (e: React.MouseEvent<Element, MouseEvent>) => { | ||
onClear?.(e); | ||
e.stopPropagation(); | ||
}; | ||
return <Input.Button placeholder={placeholder} value={value} onClear={handleClear} {...rest} />; | ||
}; | ||
|
||
export default Trigger; |
Oops, something went wrong.
c5bc076
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: