-
Couldn't load subscription status.
- Fork 1.2k
[Box] Add position and visibility properties #7755
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
41bd9b9
958ebc8
93ac7e5
36c9bdb
c48a12b
5a1b5b2
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 |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| '@shopify/polaris': patch | ||
| --- | ||
|
|
||
| Added position, opacity, top, left, right, bottom, z-index to `Box` |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,8 +20,8 @@ import { | |
| import styles from './Box.scss'; | ||
|
|
||
| type Element = 'div' | 'span' | 'section'; | ||
|
|
||
| type Overflow = 'hidden' | 'scroll'; | ||
| type Position = 'relative' | 'absolute' | 'fixed' | 'sticky'; | ||
|
|
||
| export type ColorTokenScale = | ||
| | 'text' | ||
|
|
@@ -49,13 +49,6 @@ export type BorderTokenAlias = | |
|
|
||
| type Spacing = ResponsiveProp<SpacingSpaceScale>; | ||
|
|
||
| interface Border { | ||
| blockStart: BorderTokenAlias; | ||
| blockEnd: BorderTokenAlias; | ||
| inlineStart: BorderTokenAlias; | ||
| inlineEnd: BorderTokenAlias; | ||
| } | ||
|
|
||
| export type BorderRadiusTokenScale = | ||
| | '05' | ||
| | '1' | ||
|
|
@@ -75,20 +68,6 @@ export type BackgroundColors = | |
| | ColorsActionTokenAlias | ||
| | ColorsSurfaceTokenAlias; | ||
|
|
||
| interface BorderRadius { | ||
| startStart: BorderRadiusTokenScale; | ||
| startEnd: BorderRadiusTokenScale; | ||
| endStart: BorderRadiusTokenScale; | ||
| endEnd: BorderRadiusTokenScale; | ||
| } | ||
|
|
||
| interface BorderWidth { | ||
| blockStart: ShapeBorderWidthScale; | ||
| blockEnd: ShapeBorderWidthScale; | ||
| inlineStart: ShapeBorderWidthScale; | ||
| inlineEnd: ShapeBorderWidthScale; | ||
| } | ||
|
|
||
| export interface BoxProps { | ||
| /** HTML Element type */ | ||
| as?: Element; | ||
|
|
@@ -128,11 +107,11 @@ export interface BoxProps { | |
| color?: ColorTokenScale; | ||
| /** HTML id attribute */ | ||
| id?: string; | ||
| /** Set minimum height of container */ | ||
| /** Minimum height of container */ | ||
| minHeight?: string; | ||
| /** Set minimum width of container */ | ||
| /** Minimum width of container */ | ||
| minWidth?: string; | ||
| /** Set maximum width of container */ | ||
| /** Maximum width of container */ | ||
| maxWidth?: string; | ||
| /** Clip horizontal content of children */ | ||
| overflowX?: Overflow; | ||
|
|
@@ -170,10 +149,27 @@ export interface BoxProps { | |
| paddingInlineEnd?: Spacing; | ||
| /** Shadow */ | ||
| shadow?: DepthShadowAlias; | ||
| /** Set width of container */ | ||
| /** Width of container */ | ||
| width?: string; | ||
| /** Elements to display inside box */ | ||
| children?: React.ReactNode; | ||
| // These could be moved to new layout component(s) in the future | ||
| /** Position of the box */ | ||
| position?: Position; | ||
| /** Top position of the box */ | ||
| top?: Spacing; | ||
| /** Bottom position of the box */ | ||
| right?: Spacing; | ||
| /** Left position of the box */ | ||
| bottom?: Spacing; | ||
| /** Right position of the box */ | ||
| left?: Spacing; | ||
| /** Opcity of the box */ | ||
| opacity?: string; | ||
| /** Visually hide the contents (still announced by screenreader) */ | ||
| visuallyHidden?: boolean; | ||
| /** z-index of the box */ | ||
| zIndex?: string; | ||
| } | ||
|
|
||
| export const Box = forwardRef<HTMLElement, BoxProps>( | ||
|
|
@@ -211,75 +207,62 @@ export const Box = forwardRef<HTMLElement, BoxProps>( | |
| paddingInlineEnd, | ||
| shadow, | ||
| width, | ||
| visuallyHidden, | ||
| position, | ||
| top, | ||
| right, | ||
| bottom, | ||
| left, | ||
| zIndex, | ||
| opacity, | ||
| }, | ||
| ref, | ||
| ) => { | ||
| const borders = { | ||
| blockEnd: borderBlockEnd, | ||
| inlineStart: borderInlineStart, | ||
| inlineEnd: borderInlineEnd, | ||
| blockStart: borderBlockStart, | ||
| } as Border; | ||
|
|
||
| const borderRadiuses = { | ||
| endStart: borderRadiusEndStart, | ||
| endEnd: borderRadiusEndEnd, | ||
| startStart: borderRadiusStartStart, | ||
| startEnd: borderRadiusStartEnd, | ||
| } as BorderRadius; | ||
|
|
||
| const borderWidths = { | ||
| blockStart: borderBlockStartWidth, | ||
| blockEnd: borderBlockEndWidth, | ||
| inlineStart: borderInlineStartWidth, | ||
| inlineEnd: borderInlineEndWidth, | ||
| } as BorderWidth; | ||
|
Comment on lines
-217
to
-236
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. Any reason why we were remapping these? Just seemed to add complexity to me 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. Yeah I agree. I actually removed the padding one when I added responsive padding to |
||
|
|
||
| const style = { | ||
| '--pc-box-color': color ? `var(--p-${color})` : undefined, | ||
| '--pc-box-background': background ? `var(--p-${background})` : undefined, | ||
| '--pc-box-border': border ? `var(--p-border-${border})` : undefined, | ||
| '--pc-box-border-block-end': borders.blockEnd | ||
| ? `var(--p-border-${borders.blockEnd})` | ||
| '--pc-box-border-block-end': borderBlockEnd | ||
| ? `var(--p-border-${borderBlockEnd})` | ||
| : undefined, | ||
| '--pc-box-border-inline-start': borders.inlineStart | ||
| ? `var(--p-border-${borders.inlineStart})` | ||
| '--pc-box-border-inline-start': borderInlineStart | ||
| ? `var(--p-border-${borderInlineStart})` | ||
| : undefined, | ||
| '--pc-box-border-inline-end': borders.inlineEnd | ||
| ? `var(--p-border-${borders.inlineEnd})` | ||
| '--pc-box-border-inline-end': borderInlineEnd | ||
| ? `var(--p-border-${borderInlineEnd})` | ||
| : undefined, | ||
| '--pc-box-border-block-start': borders.blockStart | ||
| ? `var(--p-border-${borders.blockStart})` | ||
| '--pc-box-border-block-start': borderBlockStart | ||
| ? `var(--p-border-${borderBlockStart})` | ||
| : undefined, | ||
| '--pc-box-border-radius': borderRadius | ||
| ? `var(--p-border-radius-${borderRadius})` | ||
| : undefined, | ||
| '--pc-box-border-radius-end-start': borderRadiuses.endStart | ||
| ? `var(--p-border-radius-${borderRadiuses.endStart})` | ||
| '--pc-box-border-radius-end-start': borderRadiusEndStart | ||
| ? `var(--p-border-radius-${borderRadiusEndStart})` | ||
| : undefined, | ||
| '--pc-box-border-radius-end-end': borderRadiuses.endEnd | ||
| ? `var(--p-border-radius-${borderRadiuses.endEnd})` | ||
| '--pc-box-border-radius-end-end': borderRadiusEndEnd | ||
| ? `var(--p-border-radius-${borderRadiusEndEnd})` | ||
| : undefined, | ||
| '--pc-box-border-radius-start-start': borderRadiuses.startStart | ||
| ? `var(--p-border-radius-${borderRadiuses.startStart})` | ||
| '--pc-box-border-radius-start-start': borderRadiusStartStart | ||
| ? `var(--p-border-radius-${borderRadiusStartStart})` | ||
| : undefined, | ||
| '--pc-box-border-radius-start-end': borderRadiuses.startEnd | ||
| ? `var(--p-border-radius-${borderRadiuses.startEnd})` | ||
| '--pc-box-border-radius-start-end': borderRadiusStartEnd | ||
| ? `var(--p-border-radius-${borderRadiusStartEnd})` | ||
| : undefined, | ||
| '--pc-box-border-width': borderWidth | ||
| ? `var(--p-border-width-${borderWidth})` | ||
| : undefined, | ||
| '--pc-box-border-block-start-width': borderWidths.blockStart | ||
| ? `var(--p-border-width-${borderWidths.blockStart})` | ||
| '--pc-box-border-block-start-width': borderBlockStartWidth | ||
| ? `var(--p-border-width-${borderBlockStartWidth})` | ||
| : undefined, | ||
| '--pc-box-border-block-end-width': borderWidths.blockEnd | ||
| ? `var(--p-border-width-${borderWidths.blockEnd})` | ||
| '--pc-box-border-block-end-width': borderBlockEndWidth | ||
| ? `var(--p-border-width-${borderBlockEndWidth})` | ||
| : undefined, | ||
| '--pc-box-border-inline-start-width': borderWidths.inlineStart | ||
| ? `var(--p-border-width-${borderWidths.inlineStart})` | ||
| '--pc-box-border-inline-start-width': borderInlineStartWidth | ||
| ? `var(--p-border-width-${borderInlineStartWidth})` | ||
| : undefined, | ||
| '--pc-box-border-inline-end-width': borderWidths.inlineEnd | ||
| ? `var(--p-border-width-${borderWidths.inlineEnd})` | ||
| '--pc-box-border-inline-end-width': borderInlineEndWidth | ||
| ? `var(--p-border-width-${borderInlineEndWidth})` | ||
| : undefined, | ||
| '--pc-box-min-height': minHeight, | ||
| '--pc-box-min-width': minWidth, | ||
|
|
@@ -313,9 +296,19 @@ export const Box = forwardRef<HTMLElement, BoxProps>( | |
| ), | ||
| '--pc-box-shadow': shadow ? `var(--p-shadow-${shadow})` : undefined, | ||
| '--pc-box-width': width, | ||
| position, | ||
| '--pc-box-top': top ? `var(--p-space-${top})` : undefined, | ||
| '--pc-box-right': right ? `var(--p-space-${right})` : undefined, | ||
| '--pc-box-bottom': bottom ? `var(--p-space-${bottom})` : undefined, | ||
| '--pc-box-left': left ? `var(--p-space-${left})` : undefined, | ||
| zIndex, | ||
| opacity, | ||
| } as React.CSSProperties; | ||
|
|
||
| const className = classNames(styles.Box); | ||
| const className = classNames( | ||
| styles.Box, | ||
| visuallyHidden && styles.visuallyHidden, | ||
| ); | ||
|
|
||
| return createElement( | ||
| as, | ||
|
|
||
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 should rename this to
insetBlockStartto be consistent with the other properties where we have started to use the logical properties naming. Same withinsetBlockEnd,insetInlineStartandinsetInlineEnd.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.
Issue to update: #7771