Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CompoundButton: Re-introducing CompoundButton using latest version of makeStyles #17534

Merged
merged 4 commits into from
Mar 24, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 70 additions & 2 deletions apps/vr-tests/src/stories/ReactButton.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { storiesOf } from '@storybook/react';
import * as React from 'react';
import Screener from 'screener-storybook/src/screener';
import { Button, ButtonProps } from '@fluentui/react-button';
import { Button, ButtonProps, CompoundButton } from '@fluentui/react-button';

import { FluentProviderDecorator, FabricDecorator } from '../utilities/index';

Expand Down Expand Up @@ -51,7 +51,7 @@ const AppearanceExample = (props: ButtonProps) => (
</>
);

storiesOf('React Button', module)
storiesOf('react-button Button', module)
.addDecorator(FabricDecorator)
.addDecorator(FluentProviderDecorator)
.addDecorator(story => (
Expand Down Expand Up @@ -93,3 +93,71 @@ storiesOf('React Button', module)
</Button>
</>
));

storiesOf('react-button CompoundButton', module)
.addDecorator(FabricDecorator)
.addDecorator(FluentProviderDecorator)
.addDecorator(story => (
<Screener
steps={new Screener.Steps()
.snapshot('default', { cropTo: '.testWrapper' })
.hover('button')
.snapshot('hover', { cropTo: '.testWrapper' })
.mouseDown('button')
.snapshot('pressed', { cropTo: '.testWrapper' })
.executeScript(
"document.getElementsByClassName('testWrapper')[0].classList.add('ms-Fabric--isFocusVisible')",
)
.executeScript("document.getElementsByTagName('button')[0].focus()")
.snapshot('focus', { cropTo: '.testWrapper' })
.executeScript(
"document.getElementsByClassName('testWrapper')[0].classList.remove('ms-Fabric--isFocusVisible')",
)
.end()}
>
{story()}
</Screener>
))
.addStory('Default', () => (
<CompoundButton secondaryContent="This is some secondary text">Hello, world</CompoundButton>
))
.addStory('Primary', () => (
<CompoundButton secondaryContent="This is some secondary text" primary>
Hello, world
</CompoundButton>
))
.addStory('Disabled', () => (
<CompoundButton secondaryContent="This is some secondary text" disabled>
Hello, world
</CompoundButton>
))
.addStory('Primary Disabled', () => (
<CompoundButton secondaryContent="This is some secondary text" primary disabled>
Hello, world
</CompoundButton>
))
.addStory('With icon before content', () => (
<CompoundButton secondaryContent="This is some secondary text" icon="X">
Hello, world
</CompoundButton>
))
.addStory('With icon after content', () => (
<CompoundButton secondaryContent="This is some secondary text" icon="X" iconPosition="after">
Hello, world
</CompoundButton>
))
.addStory('Size small', () => (
<CompoundButton secondaryContent="This is some secondary text" icon="X" size="large">
Hello, world
</CompoundButton>
))
.addStory('Size large', () => (
<CompoundButton secondaryContent="This is some secondary text" icon="X" size="large">
Hello, world
</CompoundButton>
))
.addStory('Icon only', () => (
<CompoundButton secondaryContent="This is some secondary text" icon="X">
Hello, world
</CompoundButton>
));
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "prerelease",
"comment": "CompoundButton: Re-introducing CompoundButton using latest version of makeStyles.",
"packageName": "@fluentui/react-button",
"email": "Humberto.Morimoto@microsoft.com",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "CompoundButton: Re-introducing CompoundButton using latest version of makeStyles.",
"packageName": "@fluentui/react-examples",
"email": "Humberto.Morimoto@microsoft.com",
"dependentChangeType": "patch"
}
77 changes: 65 additions & 12 deletions packages/react-button/etc/react-button.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,29 +53,34 @@ export type ButtonStyleSelectors = {
// @public (undocumented)
export type ButtonTokens = {
height: string;
maxWidth: string;
minWidth: string;
paddingX: string;
paddingY: string;
minWidth: string;
maxWidth: string;
fontSize: string;
fontWeight: number;
lineHeight: string;
iconWidth: string;
iconFontSize: string;
iconHeight: string;
iconSpacing: string;
color: string;
content2Color: string;
iconWidth: string;
background: string;
backgroundHover: string;
backgroundPressed: string;
backgroundActive: string;
color: string;
borderColor: string;
borderColorHover: string;
borderColorActive: string;
borderWidth: string;
borderRadius: string;
borderWidth: string;
shadow: string;
shadowPressed: string;
hovered: Partial<{
background: string;
borderColor: string;
color: string;
}>;
pressed: Partial<{
background: string;
borderColor: string;
color: string;
shadow: string;
}>;
};

// @public (undocumented)
Expand All @@ -86,9 +91,51 @@ export type ButtonVariantTokens = {
[variant in ButtonVariants]: Partial<ButtonTokens>;
};

// @public
export const CompoundButton: React.ForwardRefExoticComponent<CompoundButtonProps & React.RefAttributes<HTMLElement>>;

// @public (undocumented)
export interface CompoundButtonProps extends ButtonProps {
contentContainer?: ShorthandProps<React.HTMLAttributes<HTMLSpanElement>>;
secondaryContent?: ShorthandProps<React.HTMLAttributes<HTMLSpanElement>>;
}

// @public
export const compoundButtonShorthandProps: string[];

// @public (undocumented)
export interface CompoundButtonState extends Omit<CompoundButtonProps, 'children' | 'icon'>, ButtonState {
// (undocumented)
contentContainer?: ObjectShorthandProps<React.HTMLAttributes<HTMLSpanElement>>;
// (undocumented)
secondaryContent?: ObjectShorthandProps<React.HTMLAttributes<HTMLSpanElement>>;
}

// @public (undocumented)
export type CompoundButtonStyleSelectors = ButtonStyleSelectors;

// Warning: (ae-forgotten-export) The symbol "CompoundButtonBaseTokens" needs to be exported by the entry point index.d.ts
//
// @public (undocumented)
export type CompoundButtonTokens = ButtonTokens & CompoundButtonBaseTokens & {
hovered: Partial<CompoundButtonBaseTokens>;
pressed: Partial<CompoundButtonBaseTokens>;
};

// @public (undocumented)
export type CompoundButtonVariants = ButtonVariants;

// @public (undocumented)
export type CompoundButtonVariantTokens = {
[variant in CompoundButtonVariants]: Partial<CompoundButtonTokens>;
};

// @public
export const renderButton: (state: ButtonState) => JSX.Element;

// @public
export const renderCompoundButton: (state: CompoundButtonState) => JSX.Element;

// @public
export const useButton: (props: ButtonProps, ref: React.Ref<HTMLElement>, defaultProps?: ButtonProps | undefined) => ButtonState;

Expand All @@ -98,6 +145,12 @@ export const useButtonState: (draftState: ButtonState) => void;
// @public (undocumented)
export const useButtonStyles: (state: ButtonState, selectors: ButtonStyleSelectors) => void;

// @public
export const useCompoundButton: (props: CompoundButtonProps, ref: React.Ref<HTMLElement>, defaultProps?: CompoundButtonProps | undefined) => CompoundButtonState;

// @public (undocumented)
export const useCompoundButtonStyles: (state: CompoundButtonState, selectors: import("../Button").ButtonStyleSelectors) => void;


// (No @packageDocumentation comment for this package)

Expand Down
1 change: 1 addition & 0 deletions packages/react-button/src/CompoundButton.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './components/CompoundButton/index';
71 changes: 46 additions & 25 deletions packages/react-button/src/components/Button/Button.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import * as React from 'react';
import { ComponentProps, ShorthandProps } from '@fluentui/react-utilities';
import { ObjectShorthandProps } from '@fluentui/react-utilities';

/**
* {@docCategory Button}
*/
export type ButtonProps = ComponentProps &
React.ButtonHTMLAttributes<HTMLElement> & {
/**
Expand Down Expand Up @@ -63,58 +66,76 @@ export interface ButtonState extends ButtonProps {
children?: ObjectShorthandProps<React.HTMLAttributes<HTMLSpanElement>>;
}

/**
* {@docCategory Button}
*/
export type ButtonStyleSelectors = {
disabled?: boolean;
iconOnly?: boolean;
primary?: boolean;
size?: string;
};

export type ButtonVariants =
| 'base'
| 'disabled'
| 'iconOnly'
| 'primary'
| 'small'
| 'large'
// TODO: get rid of these combinations, use individual variants in matchers
| 'primaryDisabled'
| 'iconOnlySmall'
| 'iconOnlyLarge';

/**
* {@docCategory Button}
*/
export type ButtonTokens = {
height: string;
maxWidth: string;
minWidth: string;
paddingX: string;
paddingY: string;
minWidth: string;
maxWidth: string;

fontSize: string;
fontWeight: number;
lineHeight: string;

iconWidth: string;
iconFontSize: string;
iconHeight: string;
iconSpacing: string;

color: string;
content2Color: string;
iconWidth: string;

background: string;
backgroundHover: string;
backgroundPressed: string;
backgroundActive: string;
color: string;

borderColor: string;
borderColorHover: string;
borderColorActive: string;
borderWidth: string;
borderRadius: string;
borderWidth: string;

shadow: string;
shadowPressed: string;

hovered: Partial<{
background: string;
borderColor: string;
color: string;
}>;

pressed: Partial<{
background: string;
borderColor: string;
color: string;
shadow: string;
}>;
};

/**
* {@docCategory Button}
*/
export type ButtonVariants =
| 'base'
| 'disabled'
| 'iconOnly'
| 'primary'
| 'small'
| 'large'
// TODO: get rid of these combinations, use individual variants in matchers
| 'primaryDisabled'
| 'iconOnlySmall'
| 'iconOnlyLarge';

/**
* {@docCategory Button}
*/
export type ButtonVariantTokens = {
[variant in ButtonVariants]: Partial<ButtonTokens>;
};
4 changes: 2 additions & 2 deletions packages/react-button/src/components/Button/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export * from './Button.types';
export * from './Button';
export * from './Button.types';
export * from './renderButton';
export * from './useButton';
export { useButtonStyles } from './useButtonStyles';
export * from './useButtonState';
export { useButtonStyles } from './useButtonStyles';
1 change: 0 additions & 1 deletion packages/react-button/src/components/Button/useButton.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ export const useButton = (props: ButtonProps, ref: React.Ref<HTMLElement>, defau
ref: resolvedRef,
as: 'button',
icon: { as: 'span' },
content: { as: 'span', children: props.children },
loader: { as: 'span' },
},
defaultProps,
Expand Down
Loading