Repository navigation
chore: Adds internal style api v2 to popover and tooltip #5073
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
Closed
Closed
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,64 @@ | ||
| // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| import React, { useContext } from 'react'; | ||
|
|
||
| import { Checkbox, KeyValuePairs, Popover } from '~components'; | ||
|
|
||
| import AppContext, { AppContextType } from '../app/app-context'; | ||
| import { SimplePage } from '../app/templates'; | ||
|
|
||
| import styles from './style-api-v2.scss'; | ||
|
|
||
| const brand = { popover: styles['popover-brand'], dismissButton: styles['popover-brand-dismiss'] }; | ||
|
|
||
| type PageContext = React.Context< | ||
| AppContextType<{ | ||
| renderWithPortal: boolean; | ||
| }> | ||
| >; | ||
|
|
||
| export default function () { | ||
| const { | ||
| urlParams: { renderWithPortal = true }, | ||
| setUrlParams, | ||
| } = useContext(AppContext as PageContext); | ||
| const shared = { header: 'Popover header', content: 'Popover content', renderWithPortal }; | ||
| return ( | ||
| <SimplePage | ||
| title="Popover - Style API v2" | ||
| screenshotArea={{}} | ||
| settings={ | ||
| <Checkbox | ||
| checked={renderWithPortal} | ||
| onChange={({ detail }) => setUrlParams({ renderWithPortal: detail.checked })} | ||
| > | ||
| renderWithPortal | ||
| </Checkbox> | ||
| } | ||
| > | ||
| <KeyValuePairs | ||
| columns={4} | ||
| items={[ | ||
| { | ||
| type: 'pair', | ||
| label: 'Brand', | ||
| value: ( | ||
| <Popover {...shared} {...{ styleClassNames: brand }}> | ||
| Open popover | ||
| </Popover> | ||
| ), | ||
| }, | ||
| { | ||
| type: 'pair', | ||
| label: 'Borderless', | ||
| value: ( | ||
| <Popover {...shared} {...{ styleClassNames: { popover: styles['popover-borderless'] } }}> | ||
| Open popover | ||
| </Popover> | ||
| ), | ||
| }, | ||
| ]} | ||
| /> | ||
| </SimplePage> | ||
| ); | ||
| } |
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,29 @@ | ||
| /* | ||
| Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| @use '../style-api/palette' as palette; | ||
|
|
||
| .popover-brand { | ||
| --awsui-style-color: #{palette.$genai-text}; | ||
| --awsui-style-background: #{palette.$genai-surface}; | ||
| --awsui-style-border-color: #{palette.$genai}; | ||
| --awsui-style-border-width: 3px; | ||
| --awsui-style-border-radius: 8px; | ||
| } | ||
|
|
||
| .popover-borderless { | ||
| --awsui-style-background: #{palette.$subtle}; | ||
| --awsui-style-border-width: 0px; | ||
| --awsui-style-border-radius: 4px; | ||
| } | ||
|
|
||
| .popover-brand-dismiss { | ||
| --awsui-style-color: #{palette.$genai}; | ||
| --awsui-style-focus-ring-color: #{palette.$genai}; | ||
|
|
||
| &:hover { | ||
| --awsui-style-color: #{palette.$genai-hover}; | ||
| } | ||
| } | ||
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,36 @@ | ||
| // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| import React, { useRef, useState } from 'react'; | ||
|
|
||
| import { Button, Tooltip } from '~components'; | ||
|
|
||
| import { SimplePage } from '../app/templates'; | ||
|
|
||
| import styles from './style-api-v2.scss'; | ||
|
|
||
| export default function () { | ||
| const triggerRef = useRef<HTMLSpanElement>(null); | ||
| const [open, setOpen] = useState(false); | ||
| return ( | ||
| <SimplePage title="Tooltip - Style API v2" screenshotArea={{}}> | ||
| <br /> | ||
| <span | ||
| ref={triggerRef} | ||
| onMouseEnter={() => setOpen(true)} | ||
| onMouseLeave={() => setOpen(false)} | ||
| onFocus={() => setOpen(true)} | ||
| onBlur={() => setOpen(false)} | ||
| > | ||
| <Button variant="icon" iconName="copy" ariaLabel="Copy" /> | ||
| {open && ( | ||
| <Tooltip | ||
| content="ARN Copied" | ||
| getTrack={() => triggerRef.current} | ||
| onEscape={() => setOpen(false)} | ||
| {...{ styleClassNames: { tooltip: styles['tooltip-inverted'] } }} | ||
| /> | ||
| )} | ||
| </span> | ||
| </SimplePage> | ||
| ); | ||
| } |
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,13 @@ | ||
| /* | ||
| Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| @use '../style-api/palette' as palette; | ||
|
|
||
| .tooltip-inverted { | ||
| --awsui-style-color: #{palette.$text-on-accent}; | ||
| --awsui-style-background: #{palette.$accent}; | ||
| --awsui-style-border-color: #{palette.$accent}; | ||
| --awsui-style-border-radius: 2px; | ||
| } |
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 |
|---|---|---|
|
|
@@ -174,6 +174,36 @@ exports[`Style API docs definition for link matches the snapshot: link 1`] = ` | |
| } | ||
| `; | ||
|
|
||
| exports[`Style API docs definition for popover matches the snapshot: popover 1`] = ` | ||
| { | ||
| "slots": [ | ||
| { | ||
| "name": "popover", | ||
| "properties": [], | ||
| "propertyDescriptions": {}, | ||
| "tokenDescriptions": { | ||
| "background": "Background of the surface and arrow.", | ||
|
Member
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. this token is called background-color in our tracker. What is the reason to change? |
||
| "border-color": "Border color of the surface and arrow.", | ||
| "border-width": "Border width of the surface and arrow.", | ||
| }, | ||
| "tokens": [ | ||
| "background", | ||
| "border-color", | ||
| "border-width", | ||
| "border-radius", | ||
| ], | ||
| }, | ||
| { | ||
| "forwardsTo": { | ||
| "component": "button", | ||
| "slot": "root", | ||
| }, | ||
| "name": "dismissButton", | ||
| }, | ||
| ], | ||
| } | ||
| `; | ||
|
|
||
| exports[`Style API docs definition for radio-button matches the snapshot: radio-button 1`] = ` | ||
| { | ||
| "slots": [ | ||
|
|
@@ -237,6 +267,29 @@ exports[`Style API docs definition for toggle matches the snapshot: toggle 1`] = | |
| } | ||
| `; | ||
|
|
||
| exports[`Style API docs definition for tooltip matches the snapshot: tooltip 1`] = ` | ||
| { | ||
| "slots": [ | ||
| { | ||
| "name": "tooltip", | ||
| "properties": [], | ||
| "propertyDescriptions": {}, | ||
| "tokenDescriptions": { | ||
| "background": "Background of the surface and arrow.", | ||
| "border-color": "Border color of the surface and arrow.", | ||
| "border-width": "Border width of the surface and arrow.", | ||
| }, | ||
| "tokens": [ | ||
| "background", | ||
| "border-color", | ||
| "border-width", | ||
| "border-radius", | ||
| ], | ||
| }, | ||
| ], | ||
| } | ||
| `; | ||
|
|
||
| exports[`Style API docs list of components with a Style API doc matches the snapshot 1`] = ` | ||
| [ | ||
| "alert", | ||
|
|
@@ -245,7 +298,9 @@ exports[`Style API docs list of components with a Style API doc matches the snap | |
| "checkbox", | ||
| "dropdown", | ||
| "link", | ||
| "popover", | ||
| "radio-button", | ||
| "toggle", | ||
| "tooltip", | ||
| ] | ||
| `; | ||
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
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,40 @@ | ||
| // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| import React from 'react'; | ||
| import { render } from '@testing-library/react'; | ||
|
|
||
| import Popover from '../../../lib/components/popover'; | ||
| import createWrapper from '../../../lib/components/test-utils/dom'; | ||
|
|
||
| import styles from '../../../lib/components/popover/styles.css.js'; | ||
|
|
||
| function renderOpenPopover(props: Record<string, unknown>) { | ||
| const { container } = render(<Popover content="Content" header="Header" {...props} />); | ||
| const wrapper = createWrapper(container).findPopover()!; | ||
| wrapper.findTrigger().click(); | ||
| return wrapper; | ||
| } | ||
|
|
||
| describe('Popover Style API v2', () => { | ||
| test('applies styleClassNames to the popover container', () => { | ||
| const wrapper = renderOpenPopover({ styleClassNames: { popover: 'a', unknown: 'b' } }); | ||
| expect(wrapper.findByClassName(styles.container)!.getElement()).toHaveClass('a'); | ||
| expect(wrapper.find('.b')).toBeNull(); | ||
| }); | ||
|
|
||
| test('forwards the dismissButton slot to the dismiss button', () => { | ||
| const wrapper = renderOpenPopover({ styleClassNames: { dismissButton: 'a' } }); | ||
| expect(wrapper.findDismissButton()!.getElement()).toHaveClass('a'); | ||
| }); | ||
|
|
||
| test('applies styleClassNames to the popover container when rendered in a portal', () => { | ||
| const wrapper = renderOpenPopover({ renderWithPortal: true, styleClassNames: { popover: 'a' } }); | ||
| expect(wrapper.findContent({ renderWithPortal: true })).not.toBeNull(); | ||
| expect(document.body.querySelector(`.${styles.container}`)).toHaveClass('a'); | ||
| }); | ||
|
|
||
| test('does not leak the styleClassNames prop to the DOM', () => { | ||
| renderOpenPopover({ renderWithPortal: true, styleClassNames: { popover: 'a' } }); | ||
| expect(document.body.querySelector('[styleClassNames]')).toBeNull(); | ||
| }); | ||
| }); |
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
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 |
|---|---|---|
|
|
@@ -9,6 +9,7 @@ $header-row-margin-block-end: awsui.$space-xs; | |
| .body { | ||
| @include styles.styles-reset; | ||
| @include styles.text-flex-wrapping; | ||
| color: awsui.$color-text-body-default; | ||
|
Member
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. is this intentional? |
||
|
|
||
| padding-block: awsui.$space-s; | ||
| padding-inline: awsui.$space-m; | ||
|
|
||
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
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
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.
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.
we don't have such a token for popover at the moment