Skip to content

Commit

Permalink
fix(Badge): small fixes (#17087)
Browse files Browse the repository at this point in the history
* feat(Badge): fix comment useBadge hook

* feat(Badge): fix size values for useBadgeStyles

* feat(Badge): fix border width for useBadgeStyles

* feat(Badge): remove unnused theme in useBadgeStyles

* feat(Badge): update color for useBadgeStyles

* feat(Badge): remove unnused props from badge stories

* feat(Badge): remove BadgeStatus

* feat(Badge): add default values for BadgeProps

* feat(Badge): update Badge API

* Change files

* Update packages/react-badge/src/components/Badge/useBadgeStyles.ts

Co-authored-by: Ben Howell <[email protected]>

* fix(Badge): update examples

* fix(Badge): update json

Co-authored-by: Ben Howell <[email protected]>
  • Loading branch information
assuncaocharles and behowell authored Feb 23, 2021
1 parent f7066d7 commit df7def5
Show file tree
Hide file tree
Showing 10 changed files with 55 additions and 66 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "prerelease",
"comment": "feat(Badge): update Badge API",
"packageName": "@fluentui/react-badge",
"email": "[email protected]",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "prerelease",
"comment": "feat(Badge): remove unnused props from badge stories",
"packageName": "@fluentui/react-examples",
"email": "[email protected]",
"dependentChangeType": "patch"
}
16 changes: 6 additions & 10 deletions packages/react-badge/etc/react-badge.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,15 @@ import { ShorthandProps } from '@fluentui/react-utilities';
export const Badge: React.ForwardRefExoticComponent<BadgeProps & React.RefAttributes<HTMLElement>>;

// @public (undocumented)
export type BadgeAppearances = 'filled' | 'outline' | 'ghost' | 'tint';
export type BadgeAppearance = 'filled' | 'outline' | 'ghost' | 'tint';

// @public (undocumented)
export interface BadgeProps extends ComponentProps, React.HTMLAttributes<HTMLElement> {
appearance?: BadgeAppearances;
appearance?: BadgeAppearance;
icon?: ShorthandProps<HTMLElement>;
iconPosition?: 'before' | 'after';
shape?: BadgeShape;
size?: SizeValue;
status?: BadgeStatus;
size?: BadgeSize;
}

// @public (undocumented)
Expand All @@ -31,21 +30,18 @@ export type BadgeShape = 'rounded' | 'square' | 'circular';
// @public
export const badgeShorthandProps: (keyof BadgeProps)[];

// @public (undocumented)
export type BadgeSize = 'smallest' | 'smaller' | 'small' | 'medium' | 'large' | 'larger' | 'largest';

// @public (undocumented)
export interface BadgeState extends BadgeProps {
icon?: ObjectShorthandProps<HTMLSpanElement>;
ref: React.MutableRefObject<HTMLElement>;
}

// @public (undocumented)
export type BadgeStatus = 'success' | 'warning' | 'severe' | 'accent' | 'danger' | 'important' | 'informative' | 'subtle';

// @public (undocumented)
export const renderBadge: (state: BadgeState) => JSX.Element;

// @public (undocumented)
export type SizeValue = 'smallest' | 'smaller' | 'small' | 'medium' | 'large' | 'larger' | 'largest';

// @public
export const useBadge: (props: BadgeProps, ref: React.Ref<HTMLElement>, defaultProps?: BadgeProps | undefined) => BadgeState;

Expand Down
30 changes: 8 additions & 22 deletions packages/react-badge/src/components/Badge/Badge.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,12 @@ import { ComponentProps, ShorthandProps, ObjectShorthandProps } from '@fluentui/
/**
* {@docCategory Badge}
*/
export type SizeValue = 'smallest' | 'smaller' | 'small' | 'medium' | 'large' | 'larger' | 'largest';
export type BadgeSize = 'smallest' | 'smaller' | 'small' | 'medium' | 'large' | 'larger' | 'largest';

/**
* {@docCategory Badge}
*/
export type BadgeStatus =
| 'success'
| 'warning'
| 'severe'
| 'accent'
| 'danger'
| 'important'
| 'informative'
| 'subtle';

/**
* {@docCategory Badge}
*/
export type BadgeAppearances = 'filled' | 'outline' | 'ghost' | 'tint';
export type BadgeAppearance = 'filled' | 'outline' | 'ghost' | 'tint';

/**
* {@docCategory Badge}
Expand All @@ -35,23 +22,21 @@ export type BadgeShape = 'rounded' | 'square' | 'circular';
export interface BadgeProps extends ComponentProps, React.HTMLAttributes<HTMLElement> {
/**
* A Badge can be sized.
* @defaultvalue medium
*/
size?: SizeValue;

/**
* A Badge can have status styles variants
*/
status?: BadgeStatus;
size?: BadgeSize;

/**
* A Badge can be square, circular or rounded
* @defaultvalue circular
*/
shape?: BadgeShape;

/**
* A Badge can be filled, outline, ghost, inverted
* @defaultvalue filled
*/
appearance?: BadgeAppearances;
appearance?: BadgeAppearance;

/**
* Icon slot
Expand All @@ -60,6 +45,7 @@ export interface BadgeProps extends ComponentProps, React.HTMLAttributes<HTMLEle

/**
* Position for Icon to be rendered
* @defaultvalue before
*/
iconPosition?: 'before' | 'after';
}
Expand Down
2 changes: 1 addition & 1 deletion packages/react-badge/src/components/Badge/useBadge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const badgeShorthandProps: (keyof BadgeProps)[] = ['icon'];
const mergeProps = makeMergeProps<BadgeState>({ deepMerge: badgeShorthandProps });

/**
* Given user props, returns state and render function for a Badge.
* Returns the props and state required to render the component
*/
export const useBadge = (props: BadgeProps, ref: React.Ref<HTMLElement>, defaultProps?: BadgeProps): BadgeState => {
const state = mergeProps(
Expand Down
35 changes: 18 additions & 17 deletions packages/react-badge/src/components/Badge/useBadgeStyles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,76 +9,77 @@ export const useRootStyles = makeStyles<BadgeState>([
null,
theme => ({
display: 'inline-flex',
boxSizing: 'border-box',
alignItems: 'center',
justifyContent: 'center',
backgroundColor: theme.alias.color.brand.brandBackground,
borderColor: theme.alias.color.brand.brandBackground,
color: theme.global.color.white,
color: theme.alias.color.neutral.neutralForegroundInvertedAccessible,
fontWeight: theme.global.type.fontWeights.semibold,
borderWidth: '1px',
borderWidth: theme.global.strokeWidth.thin,
borderStyle: 'solid',
fontFamily: theme.global.type.fontFamilies.base,
}),
],
[
s => s.size === 'smallest',
theme => ({
{
width: '6px',
height: '6px',
fontSize: '4px',
}),
},
],
[
s => s.size === 'smaller',
theme => ({
{
width: '10px',
height: '10px',
fontSize: '6px',
}),
},
],
[
s => s.size === 'small',
theme => ({
minWidth: '4px',
{
minWidth: '16px',
height: '16px',
paddingRight: '6px',
paddingLeft: '6px',
gap: '4px',
fontSize: '8px',
}),
},
],
[
s => s.size === 'medium',
theme => ({
{
height: '20px',
minWidth: '4px',
minWidth: '20px',
gap: '4px',
paddingRight: '8px',
paddingLeft: '8px',
fontSize: '12px',
}),
},
],
[
s => s.size === 'large',
theme => ({
minWidth: '8px',
{
minWidth: '24px',
height: '24px',
paddingRight: '8px',
paddingLeft: '8px',
fontSize: '12px',
gap: '6px',
}),
},
],
[
s => s.size === 'larger' || s.size === 'largest',
theme => ({
minWidth: '8px',
minWidth: '32px',
height: '32px',
paddingRight: '12px',
paddingLeft: '12px',
gap: '6px',
fontSize: '12px',
border: '2px',
borderWidth: theme.global.strokeWidth.thick,
}),
],
[s => s.shape === 'circular', theme => ({ borderRadius: theme.global.borderRadius.circular })],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from 'react';
import { Badge, BadgeProps } from '@fluentui/react-badge';
import { Badge } from '@fluentui/react-badge';

const BadgeAppearanceExamples = (props: BadgeProps) => (
export const BadgeAppearanceExample = () => (
<>
<h2>Circular (default)</h2>
<div
Expand Down Expand Up @@ -53,5 +53,3 @@ const BadgeAppearanceExamples = (props: BadgeProps) => (
</div>
</>
);

export const BadgeAppearanceExample = () => <BadgeAppearanceExamples />;
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from 'react';
import { Badge, BadgeProps } from '@fluentui/react-badge';
import { Badge } from '@fluentui/react-badge';

const BadgeAppearanceExamples = (props: BadgeProps) => (
export const BadgeAppearanceExample = () => (
<div
style={{
display: 'flex',
Expand Down Expand Up @@ -32,5 +32,3 @@ const BadgeAppearanceExamples = (props: BadgeProps) => (
</div>
</div>
);

export const BadgeAppearanceExample = () => <BadgeAppearanceExamples />;
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from 'react';
import { Badge, BadgeProps } from '@fluentui/react-badge';
import { Badge } from '@fluentui/react-badge';

const BadgeContentExamples = (props: BadgeProps) => (
export const BadgeContentExample = () => (
<div
style={{
display: 'flex',
Expand Down Expand Up @@ -84,5 +84,3 @@ const BadgeContentExamples = (props: BadgeProps) => (
</div>
</div>
);

export const BadgeContentExample = () => <BadgeContentExamples />;
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import * as React from 'react';
import { Badge, BadgeProps } from '@fluentui/react-badge';
import { Badge } from '@fluentui/react-badge';
import { AcceptIcon } from '@fluentui/react-icons-mdl2';

const BadgeIconExamples = (props: BadgeProps) => (
export const BadgeIconExample = () => (
<div
style={{
display: 'flex',
Expand All @@ -19,5 +19,3 @@ const BadgeIconExamples = (props: BadgeProps) => (
<Badge size="largest" icon={<AcceptIcon />} />
</div>
);

export const BadgeIconExample = () => <BadgeIconExamples />;

0 comments on commit df7def5

Please sign in to comment.