-
Notifications
You must be signed in to change notification settings - Fork 285
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
Updating button style and removing docs overrides #759
Merged
Merged
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
3e85a30
Updating button style and removing docs overrides
dbanksdesign 6311d36
fixing tests
dbanksdesign e3bcb0c
Update docs/src/pages/components/button/demo.tsx
dbanksdesign 52ffbfc
fixing capitalization
dbanksdesign 8cdb2d6
Updating based on comments
dbanksdesign a4f3744
Merge branch 'main' into button-style-updates
dbanksdesign File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,114 +1,166 @@ | ||
import React from 'react'; | ||
import { Button, ButtonSizes, ButtonVariations } from '@aws-amplify/ui-react'; | ||
import { FieldLabeler } from '@/components/FieldLabeler'; | ||
import { Example } from '@/components/Example'; | ||
import * as React from 'react'; | ||
|
||
import { | ||
Button, | ||
ButtonSizes, | ||
ButtonVariations, | ||
ButtonProps, | ||
Flex, | ||
SwitchField, | ||
SelectField, | ||
TextField, | ||
} from '@aws-amplify/ui-react'; | ||
|
||
import { Demo } from '@/components/Demo'; | ||
|
||
const propsToCode = (props) => { | ||
return ( | ||
`<Button` + | ||
(props.disabled ? `\n isDisabled={${props.disabled}}` : '') + | ||
(props.fullWidth ? `\n isFullWidth={${props.fullWidth}}` : '') + | ||
(props.loading ? `\n isLoading={${props.loading}}` : '') + | ||
(props.variation | ||
? `\n variation=${JSON.stringify(props.variation)}` | ||
: '') + | ||
(props.size ? `\n size=${JSON.stringify(props.size)}` : '') + | ||
` | ||
loadingText=${JSON.stringify(props.loadingText)} | ||
onClick={() => alert('hello')} | ||
ariaLabel=${JSON.stringify(props.ariaLabel)} | ||
> | ||
Click me! | ||
</Button>` | ||
); | ||
}; | ||
|
||
const PropControls = (props) => { | ||
return ( | ||
<Flex direction="column"> | ||
<SelectField | ||
name="variation" | ||
id="variation" | ||
label="Variation" | ||
value={props.variation} | ||
onChange={(event) => | ||
props.setVariation(event.target.value as ButtonVariations) | ||
} | ||
> | ||
<option value="">Default</option> | ||
<option value="primary">Primary</option> | ||
<option value="link">Link</option> | ||
</SelectField> | ||
|
||
<SelectField | ||
name="Size" | ||
id="size" | ||
label="Size" | ||
value={props.size} | ||
onChange={(event) => props.setSize(event.target.value as ButtonSizes)} | ||
> | ||
<option value="">Default</option> | ||
<option value="small">Small</option> | ||
<option value="large">Large</option> | ||
</SelectField> | ||
|
||
<SwitchField | ||
label="isFullWidth" | ||
defaultChecked={props.fullWidth} | ||
labelPosition="end" | ||
onChange={(event) => { | ||
props.setFullWidth( | ||
event.target.checked as ButtonProps['isFullWidth'] | ||
); | ||
}} | ||
/> | ||
|
||
<SwitchField | ||
label="isDisabled" | ||
defaultChecked={props.disabled} | ||
labelPosition="end" | ||
onChange={(event) => { | ||
props.setDisabled(event.target.checked as ButtonProps['isDisabled']); | ||
}} | ||
/> | ||
|
||
<SwitchField | ||
label="isLoading" | ||
defaultChecked={props.loading} | ||
labelPosition="end" | ||
onChange={(event) => { | ||
props.setLoading(event.target.checked as ButtonProps['isLoading']); | ||
}} | ||
/> | ||
|
||
{/* <TextField | ||
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. Should we remove this commented out code? |
||
label="ariaLabel" | ||
name="ariaLabel" | ||
id="ariaLabel" | ||
value={props.ariaLabel} | ||
onChange={(event) => { | ||
props.setAriaLabel(event.target.value as ButtonProps['ariaLabel']); | ||
}} | ||
/> */} | ||
|
||
<TextField | ||
label="loadingText" | ||
name="loadingText" | ||
id="loadingText" | ||
value={props.loadingText} | ||
onChange={(event) => { | ||
props.setLoadingText( | ||
event.target.value as ButtonProps['loadingText'] | ||
); | ||
}} | ||
/> | ||
</Flex> | ||
); | ||
}; | ||
|
||
export const ButtonDemo = () => { | ||
const [disabled, setDisabled] = React.useState<boolean>(false); | ||
const [loading, setLoading] = React.useState<boolean>(false); | ||
const [fullWidth, setFullWidth] = React.useState<boolean>(false); | ||
const [loadingText, setLoadingText] = React.useState('Loading...'); | ||
const [loadingText, setLoadingText] = React.useState(''); | ||
const [ariaLabel, setAriaLabel] = React.useState<string>(''); | ||
const [variation, setVariation] = React.useState<ButtonVariations>(); | ||
const [size, setSize] = React.useState<ButtonSizes>(); | ||
|
||
const props = { | ||
disabled, | ||
loading, | ||
fullWidth, | ||
loadingText, | ||
ariaLabel, | ||
variation, | ||
size, | ||
}; | ||
const propControls = { | ||
...props, | ||
setDisabled, | ||
setLoading, | ||
setFullWidth, | ||
setLoadingText, | ||
setAriaLabel, | ||
setVariation, | ||
setSize, | ||
}; | ||
return ( | ||
<div> | ||
<h4>Button Props:</h4> | ||
<div className="flex flex-wrap gap-5 my-8"> | ||
<div className="flex items-center gap-1"> | ||
<input | ||
id="disabled" | ||
name="disabled" | ||
type="checkbox" | ||
onChange={() => setDisabled(!disabled)} | ||
/> | ||
<label htmlFor="disabled">isDisabled</label> | ||
</div> | ||
|
||
<div className="flex items-center gap-1"> | ||
<input | ||
id="fullwidth" | ||
name="fullwidth" | ||
type="checkbox" | ||
onChange={() => setFullWidth(!fullWidth)} | ||
/> | ||
<label htmlFor="fullwidth">isFullWidth</label> | ||
</div> | ||
<div className="flex items-center gap-1"> | ||
<input | ||
id="loading" | ||
name="loading" | ||
type="checkbox" | ||
onChange={() => setLoading(!loading)} | ||
/> | ||
<label htmlFor="loading">isLoading</label> | ||
</div> | ||
|
||
<FieldLabeler id="loadingText"> | ||
<input | ||
id="loadingText" | ||
type="text" | ||
value={loadingText} | ||
onChange={(event: any) => { | ||
setLoadingText(event.target.value); | ||
}} | ||
/> | ||
</FieldLabeler> | ||
|
||
<FieldLabeler id="ariaLabel"> | ||
<input | ||
id="ariaLabel" | ||
type="text" | ||
placeholder="Set aria-label text" | ||
value={ariaLabel} | ||
onChange={(event: any) => { | ||
setAriaLabel(event.target.value); | ||
}} | ||
/> | ||
</FieldLabeler> | ||
<FieldLabeler id="variation"> | ||
<select | ||
id="variation" | ||
value={variation} | ||
placeholder="Select button variation" | ||
onChange={(event) => | ||
setVariation(event.target.value as ButtonVariations) | ||
} | ||
> | ||
<option value="">default</option> | ||
<option value="primary">primary</option> | ||
<option value="link">link</option> | ||
</select> | ||
</FieldLabeler> | ||
<FieldLabeler id="size"> | ||
<select | ||
id="size" | ||
value={size} | ||
onChange={(event) => setSize(event.target.value as ButtonSizes)} | ||
> | ||
<option value="">default</option> | ||
<option value="small">small</option> | ||
<option value="large">large</option> | ||
</select> | ||
</FieldLabeler> | ||
</div> | ||
<Example> | ||
<Button | ||
className="my-favorite-button" | ||
isDisabled={disabled} | ||
isLoading={loading} | ||
loadingText={loadingText} | ||
variation={variation} | ||
size={size} | ||
onClick={() => alert('hello')} | ||
ariaLabel={ariaLabel} | ||
isFullWidth={fullWidth} | ||
type="button" | ||
> | ||
Click me! | ||
</Button> | ||
</Example> | ||
</div> | ||
<Demo | ||
code={propsToCode(props)} | ||
propControls={<PropControls {...propControls} />} | ||
> | ||
<Button | ||
isDisabled={disabled} | ||
isLoading={loading} | ||
loadingText={loadingText} | ||
variation={variation} | ||
size={size} | ||
onClick={() => alert('hello')} | ||
ariaLabel={ariaLabel} | ||
isFullWidth={fullWidth} | ||
> | ||
Click me! | ||
</Button> | ||
</Demo> | ||
); | ||
}; |
36 changes: 36 additions & 0 deletions
36
docs/src/pages/components/button/examples/ButtonThemeExample.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,36 @@ | ||
import { Flex, Button, AmplifyProvider } from '@aws-amplify/ui-react'; | ||
|
||
const theme = { | ||
name: 'button-theme', | ||
tokens: { | ||
colors: { | ||
border: { | ||
// this will affect the default button's border color | ||
primary: { value: 'black' }, | ||
}, | ||
}, | ||
components: { | ||
button: { | ||
// this will affect the font weight of all button variants | ||
fontWeight: { value: '{fontWeights.black.value}' }, | ||
// style the primary variation | ||
primary: { | ||
backgroundColor: { value: 'rebeccapurple' }, | ||
_hover: { | ||
backgroundColor: { value: 'hotpink' }, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
export const ButtonThemeExample = () => ( | ||
<AmplifyProvider theme={theme}> | ||
<Flex direction="row"> | ||
<Button>Default</Button> | ||
<Button variation="primary">Primary</Button> | ||
<Button variation="link">Link</Button> | ||
</Flex> | ||
</AmplifyProvider> | ||
); |
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 +1,2 @@ | ||
export { IconButtonExample } from './iconButton'; | ||
export { ButtonThemeExample } from './ButtonThemeExample'; |
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Will we need to keep this in sync with 152-163 below? Feels a bit awkward
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.
Yea I wonder if there is a better way to do this...