generated from amazon-archives/__template_Apache-2.0
-
Notifications
You must be signed in to change notification settings - Fork 204
feat: implement style api for textarea component #4001
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 hidden or 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,104 @@ | ||
| // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| import React, { useState } from 'react'; | ||
|
|
||
| import Textarea from '~components/textarea'; | ||
|
|
||
| import ScreenshotArea from '../utils/screenshot-area'; | ||
|
|
||
| export default function TextareaPseudoSelectorsPage() { | ||
| const [value, setValue] = useState('Test value'); | ||
| const [isInvalid, setIsInvalid] = useState(false); | ||
| const [isDisabled, setIsDisabled] = useState(false); | ||
| const [isReadOnly, setIsReadOnly] = useState(false); | ||
| const [isWarning, setIsWarning] = useState(false); | ||
| const [customStyling, setCustomStyling] = useState(false); | ||
|
|
||
| const customStyle = { | ||
| root: { | ||
| borderColor: { | ||
| default: '#3b82f6', | ||
| hover: '#2563eb', | ||
| focus: '#1d4ed8', | ||
| disabled: '#93c5fd', | ||
| readonly: '#60a5fa', | ||
| }, | ||
| borderWidth: '2px', | ||
| borderRadius: '8px', | ||
| backgroundColor: { | ||
| default: '#dbeafe', | ||
| hover: '#bfdbfe', | ||
| focus: '#bfdbfe', | ||
| disabled: '#eff6ff', | ||
| readonly: '#f0f9ff', | ||
| }, | ||
| color: { | ||
| default: '#1e40af', | ||
| hover: '#1e40af', | ||
| focus: '#1e3a8a', | ||
| disabled: '#93c5fd', | ||
| readonly: '#3b82f6', | ||
| }, | ||
| fontSize: '16px', | ||
| fontWeight: '500', | ||
| paddingBlock: '10px', | ||
| paddingInline: '14px', | ||
| }, | ||
| placeholder: { | ||
| color: '#60a5fa', | ||
| fontSize: '14px', | ||
| fontStyle: 'italic', | ||
| }, | ||
| }; | ||
|
|
||
| return ( | ||
| <> | ||
| <h1>Textarea Style API - Pseudo Selectors</h1> | ||
| <ScreenshotArea> | ||
| <Textarea | ||
| ariaLabel="Test textarea" | ||
| value={value} | ||
| onChange={event => setValue(event.detail.value)} | ||
| invalid={isInvalid} | ||
| disabled={isDisabled} | ||
| readOnly={isReadOnly} | ||
| warning={isWarning} | ||
| placeholder="Enter text" | ||
| data-testid="test-textarea" | ||
| style={customStyling ? customStyle : undefined} | ||
| /> | ||
| </ScreenshotArea> | ||
|
|
||
| <div style={{ display: 'flex', gap: '10px', flexWrap: 'wrap', marginTop: '20px' }}> | ||
| <button id="toggle-styling" onClick={() => setCustomStyling(!customStyling)} type="button"> | ||
| Toggle Custom Styling ({customStyling ? 'ON' : 'OFF'}) | ||
| </button> | ||
| <button id="toggle-invalid" onClick={() => setIsInvalid(!isInvalid)} type="button"> | ||
| Toggle Invalid ({isInvalid ? 'ON' : 'OFF'}) | ||
| </button> | ||
| <button id="toggle-disabled" onClick={() => setIsDisabled(!isDisabled)} type="button"> | ||
| Toggle Disabled ({isDisabled ? 'ON' : 'OFF'}) | ||
| </button> | ||
| <button id="toggle-readonly" onClick={() => setIsReadOnly(!isReadOnly)} type="button"> | ||
| Toggle ReadOnly ({isReadOnly ? 'ON' : 'OFF'}) | ||
| </button> | ||
| <button id="toggle-warning" onClick={() => setIsWarning(!isWarning)} type="button"> | ||
| Toggle Warning ({isWarning ? 'ON' : 'OFF'}) | ||
| </button> | ||
| <button | ||
| id="reset-all" | ||
| onClick={() => { | ||
| setCustomStyling(false); | ||
| setIsInvalid(false); | ||
| setIsDisabled(false); | ||
| setIsReadOnly(false); | ||
| setIsWarning(false); | ||
| }} | ||
| type="button" | ||
| > | ||
| Reset All | ||
| </button> | ||
| </div> | ||
| </> | ||
| ); | ||
| } | ||
This file contains hidden or 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,181 @@ | ||
| // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| import React from 'react'; | ||
|
|
||
| import Textarea, { TextareaProps } from '~components/textarea'; | ||
|
|
||
| import createPermutations from '../utils/permutations'; | ||
| import PermutationsView from '../utils/permutations-view'; | ||
| import ScreenshotArea from '../utils/screenshot-area'; | ||
|
|
||
| const permutations = createPermutations<TextareaProps>([ | ||
| { | ||
| value: ['This is an example value'], | ||
| placeholder: [''], | ||
| disabled: [false, true], | ||
| readOnly: [false, true], | ||
| onChange: [() => {}], | ||
| style: [ | ||
| { | ||
| root: { | ||
| borderColor: { | ||
| default: '#14b8a6', | ||
| hover: '#0f766e', | ||
| focus: '#0d9488', | ||
| disabled: '#99f6e4', | ||
| readonly: '#5eead4', | ||
| }, | ||
| borderWidth: '2px', | ||
| borderRadius: '8px', | ||
| backgroundColor: { | ||
| default: '#99f6e4', | ||
| hover: '#5eead4', | ||
| focus: '#5eead4', | ||
| disabled: '#5eead4', | ||
| readonly: '#ccfbf1', | ||
| }, | ||
| boxShadow: { | ||
| default: '0 1px 2px rgba(0, 0, 0, 0.05)', | ||
| hover: '0 2px 4px rgba(20, 184, 166, 0.15)', | ||
| focus: '0 0 0 4px rgba(20, 184, 166, 0.2), 0 2px 4px rgba(20, 184, 166, 0.15)', | ||
| disabled: 'none', | ||
| readonly: '0 1px 2px rgba(0, 0, 0, 0.05)', | ||
| }, | ||
| color: { | ||
| default: '#0d5c54', | ||
| hover: '#0d5c54', | ||
| focus: '#0d5c54', | ||
| disabled: '#0d5c54', | ||
| readonly: '#0f766e', | ||
| }, | ||
| fontSize: '16px', | ||
| fontWeight: '500', | ||
| paddingBlock: '12px', | ||
| paddingInline: '16px', | ||
| }, | ||
| placeholder: { | ||
| color: '#14b8a6', | ||
| fontSize: '14px', | ||
| fontStyle: 'italic', | ||
| fontWeight: '400', | ||
| }, | ||
| }, | ||
| { | ||
| root: { | ||
| borderColor: { | ||
| default: '#ef4444', | ||
| hover: '#b91c1c', | ||
| focus: '#dc2626', | ||
| disabled: '#fca5a5', | ||
| readonly: '#fca5a5', | ||
| }, | ||
| borderWidth: '2px', | ||
| borderRadius: '8px', | ||
| backgroundColor: { | ||
| default: '#fecaca', | ||
| hover: '#fca5a5', | ||
| focus: '#fca5a5', | ||
| disabled: '#fca5a5', | ||
| readonly: '#fee2e2', | ||
| }, | ||
| boxShadow: { | ||
| default: '0 1px 2px rgba(0, 0, 0, 0.05)', | ||
| hover: '0 2px 4px rgba(239, 68, 68, 0.15)', | ||
| focus: '0 0 0 4px rgba(239, 68, 68, 0.2), 0 2px 4px rgba(239, 68, 68, 0.15)', | ||
| disabled: 'none', | ||
| readonly: '0 1px 2px rgba(0, 0, 0, 0.05)', | ||
| }, | ||
| color: { | ||
| default: '#7f1d1d', | ||
| hover: '#7f1d1d', | ||
| focus: '#7f1d1d', | ||
| disabled: '#7f1d1d', | ||
| readonly: '#991b1b', | ||
| }, | ||
| }, | ||
| }, | ||
| { | ||
| root: { | ||
| borderColor: { | ||
| default: '#f59e0b', | ||
| hover: '#b45309', | ||
| focus: '#d97706', | ||
| disabled: '#fcd34d', | ||
| readonly: '#fcd34d', | ||
| }, | ||
| borderWidth: '2px', | ||
| borderRadius: '16px', | ||
| backgroundColor: { | ||
| default: '#fde68a', | ||
| hover: '#fcd34d', | ||
| focus: '#fcd34d', | ||
| disabled: '#fcd34d', | ||
| readonly: '#fef3c7', | ||
| }, | ||
| boxShadow: { | ||
| default: '0 2px 8px rgba(245, 158, 11, 0.15)', | ||
| hover: '0 6px 16px rgba(245, 158, 11, 0.25)', | ||
| focus: '0 0 0 4px rgba(245, 158, 11, 0.25), 0 6px 16px rgba(245, 158, 11, 0.3)', | ||
| disabled: 'none', | ||
| readonly: '0 2px 8px rgba(245, 158, 11, 0.15)', | ||
| }, | ||
| color: { | ||
| default: '#78350f', | ||
| hover: '#78350f', | ||
| focus: '#78350f', | ||
| disabled: '#78350f', | ||
| readonly: '#92400e', | ||
| }, | ||
| }, | ||
| }, | ||
| { | ||
| root: { | ||
| borderColor: { | ||
| default: '#10b981', | ||
| hover: '#047857', | ||
| focus: '#059669', | ||
| disabled: '#6ee7b7', | ||
| readonly: '#6ee7b7', | ||
| }, | ||
| borderWidth: '3px', | ||
| borderRadius: '0px', | ||
| backgroundColor: { | ||
| default: '#d1fae5', | ||
| hover: '#a7f3d0', | ||
| focus: '#a7f3d0', | ||
| disabled: '#a7f3d0', | ||
| readonly: '#ecfdf5', | ||
| }, | ||
| boxShadow: { | ||
| default: '0 1px 2px rgba(0, 0, 0, 0.05)', | ||
| hover: '0 2px 4px rgba(16, 185, 129, 0.1)', | ||
| focus: '0 0 0 4px rgba(16, 185, 129, 0.2), 0 2px 4px rgba(16, 185, 129, 0.15)', | ||
| disabled: 'none', | ||
| readonly: '0 1px 2px rgba(0, 0, 0, 0.05)', | ||
| }, | ||
| color: { | ||
| default: '#064e3b', | ||
| hover: '#064e3b', | ||
| focus: '#064e3b', | ||
| disabled: '#064e3b', | ||
| readonly: '#065f46', | ||
| }, | ||
| }, | ||
| }, | ||
| ], | ||
| }, | ||
| ]); | ||
|
|
||
| export default function TextareaStylePermutations() { | ||
| return ( | ||
| <> | ||
| <h1>Textarea Style permutations</h1> | ||
| <ScreenshotArea disableAnimations={true}> | ||
| <PermutationsView | ||
| permutations={permutations} | ||
| render={permutation => <Textarea ariaLabel="Textarea field" {...permutation} />} | ||
| /> | ||
| </ScreenshotArea> | ||
| </> | ||
| ); | ||
| } |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.
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.
[non-blocking] You can use the toggle button component instead
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.
Good point!