-
Notifications
You must be signed in to change notification settings - Fork 331
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat(tag): 新增可选择标签主题风格 * feat(tag): support CheckTagGroup * test: update snapshots * fix(tag): hook * feat: update common * feat: update common * chore: update snapshot * chore: update snapshot * chore: update demo and export * chore: rename index --------- Co-authored-by: Uyarn <uyarnchen@gmail.com>
- Loading branch information
Showing
15 changed files
with
4,366 additions
and
2,383 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 |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import React from 'react'; | ||
import useControlled from '../hooks/useControlled'; | ||
import { StyledProps } from '../common'; | ||
import { checkTagGroupDefaultProps } from './defaultProps'; | ||
import { CheckTagGroupValue, TdCheckTagGroupProps, TdCheckTagProps } from './type'; | ||
import useConfig from '../hooks/useConfig'; | ||
import CheckTag from './CheckTag'; | ||
|
||
export interface CheckTagGroupProps extends TdCheckTagGroupProps, StyledProps {} | ||
|
||
const CheckTagGroup = (props: CheckTagGroupProps) => { | ||
const { options, onChange } = props; | ||
const { classPrefix } = useConfig(); | ||
const componentName = `${classPrefix}-check-tag-group`; | ||
|
||
const [innerValue, setInnerValue] = useControlled(props, 'value', onChange); | ||
|
||
const onCheckTagChange: TdCheckTagProps['onChange'] = (checked, ctx) => { | ||
const { value } = ctx; | ||
if (checked) { | ||
if (props.multiple) { | ||
setInnerValue(innerValue.concat(value), { e: ctx.e, type: 'check', value }); | ||
} else { | ||
setInnerValue([value], { e: ctx.e, type: 'check', value }); | ||
} | ||
} else { | ||
let newValue: CheckTagGroupValue = []; | ||
if (props.multiple) { | ||
newValue = innerValue.filter((t) => t !== value); | ||
} | ||
setInnerValue(newValue, { e: ctx.e, type: 'uncheck', value }); | ||
} | ||
}; | ||
|
||
return ( | ||
<div className={componentName}> | ||
{options?.map((option) => ( | ||
<CheckTag | ||
key={option.value} | ||
value={option.value} | ||
data-value={option.value} | ||
checkedProps={props.checkedProps} | ||
uncheckedProps={props.uncheckedProps} | ||
checked={innerValue.includes(option.value)} | ||
onChange={onCheckTagChange} | ||
disabled={option.disabled} | ||
size={option.size} | ||
> | ||
{option.content ?? option.children ?? option.label} | ||
</CheckTag> | ||
))} | ||
</div> | ||
); | ||
}; | ||
|
||
CheckTagGroup.displayName = 'CheckTagGroup'; | ||
CheckTagGroup.defaultProps = checkTagGroupDefaultProps; | ||
|
||
export default CheckTagGroup; |
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
Oops, something went wrong.