-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Component System: Add Elevation Component #28593
Merged
Merged
Changes from 6 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
32a8cba
Add Elevation component
c1a4846
Add aria-hidden to the Elevation element
b31f9e9
Update type for borderRadius
d940822
Update snapshot tests
8bbda0c
Move elevation into ui
sarayourfriend be4256b
Update snapshot
2787ac8
Fix types
sarayourfriend e1eb92e
Update elevation stories + active vs. focus style rendering order
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
# Elevation | ||
|
||
`Elevation` is a core component that renders shadow, using the component system's shadow system. | ||
|
||
## Usage | ||
|
||
The shadow effect is generated using the `value` prop. | ||
|
||
```jsx live | ||
import { | ||
__experimentalElevation as Elevation, | ||
__experimetnalSurface as Surface, | ||
__experimetnalText as Text, | ||
__experimetnalView as View, | ||
} from '@wp-g2/components'; | ||
|
||
function Example() { | ||
return ( | ||
<Surface> | ||
<Text>Elevation</Text> | ||
<Elevation value={ 5 } /> | ||
</Surface> | ||
); | ||
} | ||
``` | ||
|
||
## Props | ||
|
||
##### active | ||
|
||
**Type**: `boolean` | ||
|
||
Renders the active (interaction) shadow value. | ||
|
||
##### borderRadius | ||
|
||
**Type**: `string`,`number` | ||
|
||
Renders the border-radius of the shadow. | ||
|
||
##### focus | ||
|
||
**Type**: `boolean` | ||
|
||
Renders the focus (interaction) shadow value. | ||
|
||
##### hover | ||
|
||
**Type**: `boolean` | ||
|
||
Renders the hover (interaction) shadow value. | ||
|
||
##### isInteractive | ||
|
||
**Type**: `boolean` | ||
|
||
Determines if hover, active, and focus shadow values should be automatically calculated and rendered. | ||
|
||
##### offset | ||
|
||
**Type**: `number` | ||
|
||
Dimensional offsets (margin) for the shadow. | ||
|
||
##### value | ||
|
||
**Type**: `number` | ||
|
||
Size of the shadow, based on the Style system's elevation system. The `value` determines the strength of the shadow, which sense of depth. | ||
In the example below, `isInteractive` is activated to give a better sense of depth. |
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,13 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { css } from '@wp-g2/styles'; | ||
|
||
export const Elevation = css` | ||
background: transparent; | ||
display: block; | ||
margin: 0 !important; | ||
pointer-events: none; | ||
position: absolute; | ||
will-change: box-shadow; | ||
`; |
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,44 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { contextConnect } from '@wp-g2/context'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { View } from '../view'; | ||
import { useElevation } from './use-elevation'; | ||
|
||
/** | ||
* | ||
* @param {import('@wp-g2/create-styles').ViewOwnProps<import('./types').Props, 'div'>} props | ||
* @param {import('react').Ref<any>} forwardedRef | ||
*/ | ||
function Elevation( props, forwardedRef ) { | ||
const otherProps = useElevation( props ); | ||
|
||
return <View aria-hidden { ...otherProps } ref={ forwardedRef } />; | ||
} | ||
|
||
/** | ||
* `Elevation` is a core component that renders shadow, using the library's shadow system. | ||
* | ||
* The shadow effect is generated using the `value` prop. | ||
* | ||
* @example | ||
* ```jsx | ||
* function Example() { | ||
* return ( | ||
* <View css={ [ ui.padding( 5 ) ] }> | ||
* <Surface css={ [ ui.padding( 5 ) ] }> | ||
* <Text>Into The Unknown</Text> | ||
* <Elevation value={ 5 } /> | ||
* </Surface> | ||
* </View> | ||
* ); | ||
* } | ||
* ``` | ||
*/ | ||
const ConnectedElevation = contextConnect( Elevation, 'Elevation' ); | ||
|
||
export default ConnectedElevation; |
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,2 @@ | ||
export { default as Elevation } from './elevation'; | ||
export * from './use-elevation'; |
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,40 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { number } from '@storybook/addon-knobs'; | ||
/** | ||
* Internal dependencies | ||
*/ | ||
import { Elevation } from '../index'; | ||
import { View } from '../../view'; | ||
|
||
export default { | ||
component: Elevation, | ||
title: 'G2 Components (Experimental)/Elevation', | ||
}; | ||
|
||
export const _default = () => { | ||
const value = number( 'value', 5 ); | ||
const hover = number( 'hover', undefined ); | ||
const focus = number( 'focus', undefined ); | ||
const active = number( 'active', undefined ); | ||
|
||
return ( | ||
<View | ||
css={ { | ||
padding: '20vh', | ||
position: 'relative', | ||
margin: '20vh auto 10vw', | ||
maxWidth: 400, | ||
} } | ||
> | ||
<Elevation | ||
isInteractive | ||
value={ value } | ||
hover={ hover } | ||
focus={ focus } | ||
active={ active } | ||
/> | ||
</View> | ||
diegohaz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
); | ||
}; |
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.
Does this component accept a children prop? Is it possible that someone uses this component like this by mistake?
If that's the case, I would whether not accept a children prop or warn against it. If there's a use case for children prop, I would use
role="presentation"
instead ofaria-hidden
(the difference is thataria-hidden
will disable the whole subtree, whereasrole="presentation"
will only disable that element).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.
Ooo! Thanks for the feedback.
Elevation
actually shouldn't acceptchildren
😱 .(@sarayourfriend how would we adjust the types for that? I think this may be one of the few new components that don't accept
children
)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.
Oh, interesting. I'll do some tinkering.