-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Button: Creating ActionButton variant and cleaning styling #8645
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"changes": [ | ||
{ | ||
"packageName": "@uifabric/experiments", | ||
"comment": "Button: Creating ActionButton variant and cleaning styling.", | ||
"type": "minor" | ||
} | ||
], | ||
"packageName": "@uifabric/experiments", | ||
"email": "[email protected]" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import * as React from 'react'; | ||
import { Button } from './Button'; | ||
import { IButtonComponent, IButtonTokenReturnType } from './Button.types'; | ||
import { ButtonVariantsType } from './ButtonVariants.types'; | ||
import { FontWeights } from '../../Styling'; | ||
|
||
const baseTokens: IButtonComponent['tokens'] = (props, theme): IButtonTokenReturnType => { | ||
const { palette } = theme; | ||
|
||
return { | ||
backgroundColor: 'transparent', | ||
backgroundColorHovered: 'transparent', | ||
backgroundColorPressed: 'transparent', | ||
borderColor: 'transparent', | ||
color: palette.neutralPrimary, | ||
colorHovered: palette.themePrimary, | ||
colorPressed: palette.black, | ||
contentPadding: '0px 8px', | ||
height: '40px', | ||
iconColor: palette.neutralPrimary, | ||
iconColorHovered: palette.themePrimary, | ||
iconColorPressed: palette.black, | ||
textWeight: FontWeights.regular | ||
}; | ||
}; | ||
|
||
const disabledTokens: IButtonComponent['tokens'] = (props, theme): IButtonTokenReturnType => { | ||
const { palette } = theme; | ||
|
||
return { | ||
color: palette.neutralTertiary, | ||
colorHovered: palette.neutralTertiary, | ||
colorPressed: palette.neutralTertiary, | ||
iconColor: palette.neutralTertiary, | ||
iconColorHovered: palette.neutralTertiary, | ||
iconColorPressed: palette.neutralTertiary | ||
}; | ||
}; | ||
|
||
export const ActionButtonTokens: IButtonComponent['tokens'] = (props, theme): IButtonTokenReturnType => [ | ||
baseTokens, | ||
props.disabled && disabledTokens | ||
]; | ||
|
||
export const ActionButton: ButtonVariantsType = props => { | ||
const { text, iconProps, ...rest } = props; | ||
|
||
return <Button stack={{ horizontalAlign: 'start' }} content={text} icon={iconProps} tokens={ActionButtonTokens} {...rest} />; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ import { Button } from './Button'; | |
import { ButtonVariantsType } from './ButtonVariants.types'; | ||
|
||
export const DefaultButton: ButtonVariantsType = props => { | ||
const { text, ...rest } = props; | ||
const { text, iconProps, ...rest } = props; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I didn't catch this in the other PR but maybe text is another prop that could be deprecated in master and removed in Fabric 7. |
||
|
||
return <Button content={text} {...rest} />; | ||
return <Button content={text} icon={iconProps} {...rest} />; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ import { Button } from './Button'; | |
import { ButtonVariantsType } from './ButtonVariants.types'; | ||
|
||
export const PrimaryButton: ButtonVariantsType = props => { | ||
const { text, ...rest } = props; | ||
const { text, iconProps, ...rest } = props; | ||
|
||
return <Button primary content={text} {...rest} />; | ||
return <Button primary content={text} icon={iconProps} {...rest} />; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is the name that appears in the hierarchy for these variants? If it's All of this is just driving need for an There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I think only There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The other button variants appear as I'll add a note to #8331. The only other solution I can think of is to create new variants using |
||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import * as React from 'react'; | ||
import { ActionButton, DefaultButton, PrimaryButton } from '../index'; | ||
import { Stack } from 'office-ui-fabric-react'; | ||
|
||
const tokens = { | ||
sectionStack: { | ||
childrenGap: 32 | ||
}, | ||
buttonStack: { | ||
childrenGap: 12 | ||
} | ||
}; | ||
|
||
const alertClicked = (): void => { | ||
alert('Clicked'); | ||
}; | ||
|
||
const ButtonStack = (props: { children: JSX.Element[] | JSX.Element }) => ( | ||
<Stack horizontal disableShrink tokens={tokens.buttonStack}> | ||
{props.children} | ||
</Stack> | ||
); | ||
|
||
// tslint:disable:jsx-no-lambda | ||
export class ButtonVariantsExample extends React.Component<{}, {}> { | ||
public render(): JSX.Element { | ||
return ( | ||
<Stack tokens={tokens.sectionStack}> | ||
<Stack tokens={tokens.buttonStack}> | ||
<ButtonStack> | ||
<DefaultButton text="Default button" onClick={alertClicked} /> | ||
<DefaultButton disabled text="Disabled default button" onClick={alertClicked} /> | ||
<PrimaryButton text="Primary button" onClick={alertClicked} /> | ||
<PrimaryButton disabled text="Disabled primary button" onClick={alertClicked} /> | ||
</ButtonStack> | ||
<ButtonStack> | ||
<ActionButton text="Action button" onClick={alertClicked} /> | ||
<ActionButton disabled text="Disabled action button" onClick={alertClicked} /> | ||
</ButtonStack> | ||
</Stack> | ||
</Stack> | ||
); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
export * from './Button'; | ||
export * from './Button.types'; | ||
export * from './ButtonVariants.types'; | ||
export * from './ActionButton'; | ||
export * from './DefaultButton'; | ||
export * from './PrimaryButton'; |
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.
I think we should consider marking this prop as deprecated in master and then remove it for Fabric 7 release, which would mean we wouldn't need to add it here.
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.
But how can we mark it as deprecated in the current
Button
in oufr if we still don't offer an alternative in that production component?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.
By adding a
content
prop.. should be relatively easy. Unless we don't think that's a good permanent name for Button content, in which case we have a larger problem to address.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.
And then we do the same for
iconProps
? Deprecate it in favor of a newicon
prop?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.
Possibly. It's either that or we carry over duplicate names for props even in Fabric 7 which seems cumbersome to take on for all of 7.x. I wonder what @dzearing thinks.