-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Tag/TagButton init component setup (#27102)
* add raw html * add types and update render to use slots * init slots and layout setup for tag * init pass on Tag button * fix dep version * add icons to package.json * api update * update tests * Update packages/react-components/react-tags/src/components/Tag/Tag.types.ts Co-authored-by: Esteban Munoz Facusse <[email protected]> * Update packages/react-components/react-tags/src/components/Tag/useTag.tsx Co-authored-by: Esteban Munoz Facusse <[email protected]> * Update packages/react-components/react-tags/src/components/TagButton/TagButton.types.ts Co-authored-by: Esteban Munoz Facusse <[email protected]> * Update packages/react-components/react-tags/src/components/TagButton/renderTagButton.tsx Co-authored-by: Esteban Munoz Facusse <[email protected]> * remove unnecessary named columns * Update packages/react-components/react-tags/src/components/Tag/useTag.tsx Co-authored-by: Sean Monahan <[email protected]> * Update packages/react-components/react-tags/src/components/TagButton/useTagButton.tsx Co-authored-by: Sean Monahan <[email protected]> * bmp react utils to match master * Update packages/react-components/react-tags/package.json * Update api.md * Update test snapshot with react-icon update --------- Co-authored-by: Esteban Munoz Facusse <[email protected]> Co-authored-by: Sean Monahan <[email protected]> Co-authored-by: Amber <[email protected]> Co-authored-by: Amber <[email protected]>
- Loading branch information
1 parent
1998266
commit a3edb5d
Showing
18 changed files
with
503 additions
and
94 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
23 changes: 18 additions & 5 deletions
23
packages/react-components/react-tags/src/components/Tag/Tag.types.ts
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,17 +1,30 @@ | ||
import type { ComponentProps, ComponentState, Slot } from '@fluentui/react-utilities'; | ||
import { Avatar } from '@fluentui/react-avatar'; | ||
|
||
export type TagSlots = { | ||
root: Slot<'div'>; | ||
root: NonNullable<Slot<'div'>>; | ||
content?: Slot<'span'>; | ||
avatar?: Slot<typeof Avatar>; | ||
icon?: Slot<'span'>; | ||
primaryText?: Slot<'span'>; | ||
secondaryText?: Slot<'span'>; | ||
dismissButton?: NonNullable<Slot<'button'>>; | ||
}; | ||
|
||
/** | ||
* Tag Props | ||
*/ | ||
export type TagProps = ComponentProps<TagSlots> & {}; | ||
export type TagProps = ComponentProps<TagSlots> & { | ||
size?: 'extra-small' | 'small' | 'medium'; | ||
shape?: 'rounded' | 'circular'; | ||
appearance?: 'filled-darker' | 'filled-lighter' | 'tint' | 'outline'; | ||
disabled?: boolean; | ||
checked?: boolean; | ||
dismissable?: boolean; | ||
}; | ||
|
||
/** | ||
* State used in rendering Tag | ||
*/ | ||
export type TagState = ComponentState<TagSlots>; | ||
// TODO: Remove semicolon from previous line, uncomment next line, and provide union of props to pick from TagProps. | ||
// & Required<Pick<TagProps, 'propName'>> | ||
export type TagState = ComponentState<TagSlots> & | ||
Required<Pick<TagProps, 'appearance' | 'checked' | 'disabled' | 'dismissable' | 'shape' | 'size'>>; |
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
28 changes: 0 additions & 28 deletions
28
packages/react-components/react-tags/src/components/Tag/useTag.ts
This file was deleted.
Oops, something went wrong.
60 changes: 60 additions & 0 deletions
60
packages/react-components/react-tags/src/components/Tag/useTag.tsx
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,60 @@ | ||
import * as React from 'react'; | ||
import { getNativeElementProps, resolveShorthand } from '@fluentui/react-utilities'; | ||
import { Dismiss16Filled } from '@fluentui/react-icons'; | ||
import { Avatar } from '@fluentui/react-avatar'; | ||
import type { TagProps, TagState } from './Tag.types'; | ||
|
||
/** | ||
* Create the state required to render Tag. | ||
* | ||
* The returned state can be modified with hooks such as useTagStyles_unstable, | ||
* before being passed to renderTag_unstable. | ||
* | ||
* @param props - props from this instance of Tag | ||
* @param ref - reference to root HTMLElement of Tag | ||
*/ | ||
export const useTag_unstable = (props: TagProps, ref: React.Ref<HTMLElement>): TagState => { | ||
const { | ||
checked = false, | ||
disabled = false, | ||
dismissable = false, | ||
shape = 'rounded', | ||
size = 'medium', | ||
appearance = 'filled-lighter', | ||
} = props; | ||
|
||
return { | ||
components: { | ||
root: 'div', | ||
content: 'span', | ||
avatar: Avatar, | ||
icon: 'span', | ||
primaryText: 'span', | ||
secondaryText: 'span', | ||
dismissButton: 'button', | ||
}, | ||
checked, | ||
disabled, | ||
dismissable, | ||
shape, | ||
size, | ||
appearance, | ||
root: getNativeElementProps('div', { | ||
ref, | ||
...props, | ||
}), | ||
content: resolveShorthand(props.content, { required: true }), | ||
avatar: resolveShorthand(props.avatar), | ||
icon: resolveShorthand(props.icon), | ||
primaryText: resolveShorthand(props.primaryText), | ||
secondaryText: resolveShorthand(props.secondaryText), | ||
dismissButton: resolveShorthand(props.dismissButton, { | ||
required: true, | ||
defaultProps: { | ||
disabled, | ||
type: 'button', | ||
children: <Dismiss16Filled />, | ||
}, | ||
}), | ||
}; | ||
}; |
Oops, something went wrong.