-
Notifications
You must be signed in to change notification settings - Fork 377
feat(divider): add support for switching orientation at various breakpoints #7285
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
Changes from all commits
901b0f6
a888763
b1e57d4
76b24c6
78f404d
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 |
|---|---|---|
|
|
@@ -14,7 +14,7 @@ export interface DividerProps extends React.HTMLProps<HTMLElement> { | |
| className?: string; | ||
| /** The component type to use */ | ||
| component?: 'hr' | 'li' | 'div'; | ||
| /** Flag to indicate the divider is vertical (must be in a flex layout) */ | ||
| /** @deprecated Use `orientation` instead. Flag to indicate the divider is vertical (must be in a flex layout) */ | ||
| isVertical?: boolean; | ||
| /** Insets at various breakpoints. */ | ||
| inset?: { | ||
|
|
@@ -25,13 +25,23 @@ export interface DividerProps extends React.HTMLProps<HTMLElement> { | |
| xl?: 'insetNone' | 'insetXs' | 'insetSm' | 'insetMd' | 'insetLg' | 'insetXl' | 'inset2xl' | 'inset3xl'; | ||
| '2xl'?: 'insetNone' | 'insetXs' | 'insetSm' | 'insetMd' | 'insetLg' | 'insetXl' | 'inset2xl' | 'inset3xl'; | ||
| }; | ||
| /** Indicates how the divider will display at various breakpoints. Vertical divider must be in a flex layout. */ | ||
| orientation?: { | ||
|
Contributor
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 think we want to add a
Contributor
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. @tlabaj yep, that would be inline with how we handle these breakpoint modifiers in other components. |
||
| default?: 'vertical' | 'horizontal'; | ||
| sm?: 'vertical' | 'horizontal'; | ||
| md?: 'vertical' | 'horizontal'; | ||
| lg?: 'vertical' | 'horizontal'; | ||
| xl?: 'vertical' | 'horizontal'; | ||
| '2xl'?: 'vertical' | 'horizontal'; | ||
| }; | ||
| } | ||
|
|
||
| export const Divider: React.FunctionComponent<DividerProps> = ({ | ||
| className, | ||
| component = DividerVariant.hr, | ||
| isVertical = false, | ||
| inset, | ||
| orientation, | ||
|
Contributor
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. can we or should we set the default orientation alongside the other default props? Before,
Contributor
Author
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. Setting the default orientation shouldn't be necessary here since Divider defaults to horizontal! 👍 |
||
| ...props | ||
| }: DividerProps) => { | ||
| const Component: any = component; | ||
|
|
@@ -42,6 +52,7 @@ export const Divider: React.FunctionComponent<DividerProps> = ({ | |
| styles.divider, | ||
| isVertical && styles.modifiers.vertical, | ||
| formatBreakpointMods(inset, styles), | ||
| formatBreakpointMods(orientation, styles), | ||
| className | ||
| )} | ||
| {...(component !== 'hr' && { role: 'separator' })} | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| import React from 'react'; | ||
| import { Divider, Flex, FlexItem } from '@patternfly/react-core'; | ||
|
|
||
| export const DividerOrientationVariousBreakpoints: React.FunctionComponent = () => ( | ||
| <Flex> | ||
| <FlexItem>first item</FlexItem> | ||
| <Divider | ||
| orientation={{ | ||
| default: 'vertical', | ||
| sm: 'horizontal', | ||
| md: 'vertical', | ||
| lg: 'horizontal', | ||
| xl: 'vertical', | ||
| '2xl': 'horizontal' | ||
| }} | ||
| /> | ||
| <FlexItem>second item</FlexItem> | ||
| </Flex> | ||
| ); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,14 +5,16 @@ export const DividerVerticalFlexInsetVariousBreakpoints: React.FunctionComponent | |
| <Flex> | ||
| <FlexItem>first item</FlexItem> | ||
| <Divider | ||
| isVertical | ||
| orientation={{ | ||
| default: 'vertical' | ||
| }} | ||
| inset={{ | ||
| default: 'insetMd', | ||
| md: 'insetNone', | ||
| lg: 'insetSm', | ||
| xl: 'insetXs' | ||
| }} | ||
| /> | ||
| <FlexItem>first item</FlexItem> | ||
| <FlexItem>second item</FlexItem> | ||
|
Contributor
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. 🤩 |
||
| </Flex> | ||
| ); | ||
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.
Just a nit and outside the scope, but since we're copying this doc comment, is the bit about it needing to be in a flex layout necessary? I'm assuming so since the vertical divider doesn't really work on its own like the default/horiz variant. If we're going to leave it, technically the parent (or divider itself) just needs a height of some sort, or the parent needs to support
align-itemsso thatalign-items: stretchon the divider works (this is why it works in flex, but that is supported in grid, too).Here are a few examples - https://codepen.io/mcoker/pen/ZErzBeg
This is what the vertical divider core docs say
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.
Thank you for your helpful comment and clarification here @mcoker ! It looks like the vertical variant only renders in react when it's placed within a
Flexlayout -- the extra detail in the prop description lets the consumer know they'll need it.Is setting the height and/or supporting
align-itemssomething that can be done in react, or would that need to be done in core? If agreeable with you, I'd be happy to open another issue so we can get this merged 🙂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.
@jenny-s51 gotcha! I guess it's a little confusing to me since it can be used outside of a CSS flex layout, but mostly works in the
<Flex>react layout.