Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/kind-carrots-leave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@shopify/polaris': minor
---

Added support for `overflowX`, `overflowY`, and `width` props to `Box`
7 changes: 7 additions & 0 deletions polaris-react/src/components/Box/Box.scss
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@
--pc-box-border-top: initial;
--pc-box-color: initial;
--pc-box-max-width: initial;
--pc-box-overflow-x: initial;
--pc-box-overflow-y: initial;
--pc-box-padding-bottom: initial;
--pc-box-padding-left: initial;
--pc-box-padding-right: initial;
--pc-box-padding-top: initial;
--pc-box-width: initial;
background-color: var(--pc-box-background);
box-shadow: var(--pc-box-shadow);
border-bottom-left-radius: var(--pc-box-border-radius-bottom-left);
Expand All @@ -28,9 +31,13 @@
border-top: var(--pc-box-border-top);
color: var(--pc-box-color);
max-width: var(--pc-box-max-width);
overflow-x: var(--pc-box-overflow-x);
overflow-y: var(--pc-box-overflow-y);
padding-bottom: var(--pc-box-padding-bottom);
padding-left: var(--pc-box-padding-left);
padding-right: var(--pc-box-padding-right);
padding-top: var(--pc-box-padding-top);
width: var(--pc-box-width);
/* stylelint-enable declaration-block-no-redundant-longhand-properties */
-webkit-overflow-scrolling: touch;
}
18 changes: 16 additions & 2 deletions polaris-react/src/components/Box/Box.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import styles from './Box.scss';

type Element = 'div' | 'span';

type Overflow = 'hidden' | 'scroll';

export type BackgroundColorTokenScale =
| 'action-critical'
| 'action-critical-depressed'
Expand Down Expand Up @@ -164,8 +166,12 @@ export interface BoxProps {
color?: ColorTokenScale;
/** HTML id attribute */
id?: string;
/** Spacing outside of container */
/** Set maximum width of container */
maxWidth?: string;
/** Clip horizontal content of children */
overflowX?: Overflow;
/** Clip vertical content of children */
overflowY?: Overflow;
/** Spacing around children */
padding?: SpacingSpaceScale;
/** Bottom spacing around children */
Expand All @@ -178,6 +184,8 @@ export interface BoxProps {
paddingTop?: SpacingSpaceScale;
/** Shadow */
shadow?: DepthShadowAlias;
/** Set width of container */
width?: string;
}

export const Box = forwardRef<HTMLElement, BoxProps>(
Expand All @@ -199,12 +207,15 @@ export const Box = forwardRef<HTMLElement, BoxProps>(
color,
id,
maxWidth,
overflowX,
overflowY,
padding,
paddingBottom,
paddingLeft,
paddingRight,
paddingTop,
shadow,
width,
},
ref,
) => {
Expand Down Expand Up @@ -270,7 +281,9 @@ export const Box = forwardRef<HTMLElement, BoxProps>(
}
: undefined),
...(color ? {'--pc-box-color': `var(--p-${color})`} : undefined),
...(maxWidth ? {'--pc-box-max-width': `${maxWidth}px`} : undefined),
...(maxWidth ? {'--pc-box-max-width': `${maxWidth}`} : undefined),
...(overflowX ? {'--pc-box-overflow-x': `${overflowX}`} : undefined),
...(overflowY ? {'--pc-box-overflow-y': `${overflowY}`} : undefined),
...(paddings.bottom
? {'--pc-box-padding-bottom': `var(--p-space-${paddings.bottom})`}
: undefined),
Expand All @@ -286,6 +299,7 @@ export const Box = forwardRef<HTMLElement, BoxProps>(
...(shadow
? {'--pc-box-shadow': `var(--p-shadow-${shadow})`}
: undefined),
...(width ? {'--pc-box-max-width': `${width}`} : undefined),
} as React.CSSProperties;

const className = classNames(styles.Box);
Expand Down