Skip to content
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

Add min-width support to Box DS component; Fix Blockaid Security Alert overflow issue; Fix missing Box width-max breakpoint styles #21317

Merged
merged 16 commits into from
Oct 13, 2023
Merged
Show file tree
Hide file tree
Changes from 5 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
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ exports[`Security Provider Banner Alert should match snapshot 1`] = `
class="mm-box mm-icon mm-icon--size-lg mm-box--display-inline-block mm-box--color-error-default"
style="mask-image: url('./images/icons/danger.svg');"
/>
<div>
<div
class="mm-box mm-box--min-width-0"
>
<p
class="mm-box mm-text mm-text--body-lg-medium mm-box--color-text-default"
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ exports[`Blockaid Banner Alert should render 'danger' UI when securityAlertRespo
class="mm-box mm-icon mm-icon--size-lg mm-box--display-inline-block mm-box--color-error-default"
style="mask-image: url('./images/icons/danger.svg');"
/>
<div>
<div
class="mm-box mm-box--min-width-0"
>
<p
class="mm-box mm-text mm-text--body-lg-medium mm-box--color-text-default"
>
Expand Down Expand Up @@ -55,7 +57,9 @@ exports[`Blockaid Banner Alert should render 'warning' UI when securityAlertResp
class="mm-box mm-icon mm-icon--size-lg mm-box--display-inline-block mm-box--color-warning-default"
style="mask-image: url('./images/icons/danger.svg');"
/>
<div>
<div
class="mm-box mm-box--min-width-0"
>
<p
class="mm-box mm-text mm-text--body-lg-medium mm-box--color-text-default"
>
Expand All @@ -79,7 +83,9 @@ exports[`Blockaid Banner Alert should render 'warning' UI when securityAlertResp
class="mm-box mm-icon mm-icon--size-lg mm-box--display-inline-block mm-box--color-warning-default"
style="mask-image: url('./images/icons/danger.svg');"
/>
<div>
<div
class="mm-box mm-box--min-width-0"
>
<p
class="mm-box mm-text mm-text--body-lg-medium mm-box--color-text-default"
>
Expand Down Expand Up @@ -126,7 +132,9 @@ exports[`Blockaid Banner Alert should render details when provided 1`] = `
class="mm-box mm-icon mm-icon--size-lg mm-box--display-inline-block mm-box--color-warning-default"
style="mask-image: url('./images/icons/danger.svg');"
/>
<div>
<div
class="mm-box mm-box--min-width-0"
>
<p
class="mm-box mm-text mm-text--body-lg-medium mm-box--color-text-default"
>
Expand Down Expand Up @@ -158,7 +166,7 @@ exports[`Blockaid Banner Alert should render details when provided 1`] = `
class="disclosure__content normal"
>
<ul
class="mm-box mm-text mm-text--body-md mm-box--color-text-default"
class="mm-box mm-text mm-text--body-md mm-text--overflow-wrap-break-word mm-box--color-text-default"
>
<li>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ import PropTypes from 'prop-types';
import { captureException } from '@sentry/browser';

import { Text } from '../../../component-library';
import { Severity } from '../../../../helpers/constants/design-system';
import {
OverflowWrap,
Severity,
} from '../../../../helpers/constants/design-system';
import { I18nContext } from '../../../../contexts/i18n';

import {
Expand Down Expand Up @@ -64,7 +67,7 @@ function BlockaidBannerAlert({ securityAlertResponse, ...props }) {
const description = t(REASON_TO_DESCRIPTION_TKEY[reason] || 'other');

const details = features?.length ? (
<Text as="ul">
<Text as="ul" overflowWrap={OverflowWrap.BreakWord}>
{features.map((feature, i) => (
<li key={`blockaid-detail-${i}`}>{feature}</li>
))}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ exports[`BannerAlert should render BannerAlert element correctly 1`] = `
class="mm-box mm-icon mm-icon--size-lg mm-box--display-inline-block mm-box--color-primary-default"
style="mask-image: url('./images/icons/info.svg');"
/>
<div>
<div
class="mm-box mm-box--min-width-0"
>
<p
class="mm-box mm-text mm-text--body-lg-medium mm-box--color-text-default"
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ exports[`BannerBase should render BannerBase element correctly 1`] = `
class="mm-box mm-banner-base mm-box--padding-3 mm-box--display-flex mm-box--gap-2 mm-box--background-color-background-default mm-box--rounded-sm"
data-testid="banner-base"
>
<div>
<div
class="mm-box mm-box--min-width-0"
>
<p
class="mm-box mm-text mm-text--body-lg-medium mm-box--color-text-default"
>
Expand Down
7 changes: 5 additions & 2 deletions ui/components/component-library/banner-base/banner-base.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { useI18nContext } from '../../../hooks/useI18nContext';

import {
BackgroundColor,
BlockSize,
BorderRadius,
Display,
TextVariant,
Expand Down Expand Up @@ -55,7 +56,8 @@ export const BannerBase: BannerBaseComponent = React.forwardRef(
>
{startAccessory && <>{startAccessory}</>}

<div>
{/* min-Width: 0 style is used to prevent grid/flex blowout */}
<Box minWidth={BlockSize.Zero}>
{title && (
<Text variant={TextVariant.bodyLgMedium} {...titleProps}>
{title}
Expand All @@ -76,7 +78,8 @@ export const BannerBase: BannerBaseComponent = React.forwardRef(
{actionButtonLabel}
</ButtonLink>
)}
</div>
</Box>

{onClose && (
<ButtonIcon
className="mm-banner-base__close-button"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ exports[`BannerTip should render BannerTip element correctly 1`] = `
src="images/fox-greeting.png"
/>
</div>
<div>
<div
class="mm-box mm-box--min-width-0"
>
<p
class="mm-box mm-text mm-text--body-lg-medium mm-box--color-text-default"
>
Expand Down
59 changes: 57 additions & 2 deletions ui/components/component-library/box/box.scss
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,9 @@ $attributesToApplyExtraProperties: margin;
width: 100%;
}

&--min-width-full {
min-width: 100%;
}

&--height-full {
height: 100%;
Expand All @@ -241,6 +244,10 @@ $attributesToApplyExtraProperties: margin;
width: $value;
}

&--min-width-#{$fraction} {
min-width: $value;
}

&--height-#{$fraction} {
height: $value;
}
Expand All @@ -252,6 +259,10 @@ $attributesToApplyExtraProperties: margin;
&--#{$breakpoint}\:width-#{$fraction} {
width: $value;
}
&--#{$breakpoint}\:min-width-#{$fraction} {
min-width: $value;
}

&--#{$breakpoint}\:height-#{$fraction} {
height: $value;
}
Expand All @@ -268,6 +279,14 @@ $attributesToApplyExtraProperties: margin;
}
}

@each $breakpoint, $min-width in $screen-sizes-map {
@media screen and (min-width: $min-width) {
&--#{$breakpoint}\:min-width-full {
min-width: 100%;
}
}
}

// breakpoint classes
@each $breakpoint, $min-width in $screen-sizes-map {
@media screen and (min-width: $min-width) {
Expand Down Expand Up @@ -301,6 +320,18 @@ $attributesToApplyExtraProperties: margin;
}
}

&--min-width-screen {
min-width: 100vw;
}
// breakpoint classes
@each $breakpoint, $min-width in $screen-sizes-map {
@media screen and (min-width: $min-width) {
&--#{$breakpoint}\:min-width-screen {
min-width: 100vw;
}
}
}

&--height-max {
height: max-content;
}
Expand All @@ -319,8 +350,20 @@ $attributesToApplyExtraProperties: margin;
// breakpoint classes
@each $breakpoint, $min-width in $screen-sizes-map {
@media screen and (min-width: $min-width) {
&--#{$breakpoint}\:height-max {
height: max-content;
&--#{$breakpoint}\:width-max {
width: max-content;
}
}
}

&--min-width-max {
min-width: max-content;
}
// breakpoint classes
@each $breakpoint, $min-width in $screen-sizes-map {
@media screen and (min-width: $min-width) {
&--#{$breakpoint}\:min-width-max {
min-width: max-content;
}
}
}
Expand Down Expand Up @@ -349,6 +392,18 @@ $attributesToApplyExtraProperties: margin;
}
}

&--min-width-min {
min-width: min-content;
}
// breakpoint classes
@each $breakpoint, $min-width in $screen-sizes-map {
@media screen and (min-width: $min-width) {
&--#{$breakpoint}\:min-width-min {
min-width: min-content;
}
}
}

// text
@each $alignment in design-system.$text-align {
&--text-align-#{$alignment} {
Expand Down
6 changes: 6 additions & 0 deletions ui/components/component-library/box/box.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ export default {
control: 'multi-select',
table: { category: 'display' },
},
minWidth: {
options: Object.values(BlockSize),
control: 'multi-select',
table: { category: 'display' },
},
height: {
options: Object.values(BlockSize),
control: 'select',
Expand Down Expand Up @@ -224,6 +229,7 @@ BoxDefaultStory.args = {
display: Display.Flex,
justifyContent: JustifyContent.center,
alignItems: AlignItems.center,
minWidth: BlockSize.Zero,
width: BlockSize.Half,
height: BlockSize.Half,
borderColor: BorderColor.borderDefault,
Expand Down
2 changes: 2 additions & 0 deletions ui/components/component-library/box/box.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ export const Box: BoxComponent = React.forwardRef(
gap,
display,
width,
minWidth,
height,
children,
className = '',
Expand Down Expand Up @@ -208,6 +209,7 @@ export const Box: BoxComponent = React.forwardRef(
generateClassNames('align-items', alignItems, isValidString),
generateClassNames('text-align', textAlign, isValidString),
generateClassNames('width', width, isValidString),
generateClassNames('min-width', minWidth, isValidString),
generateClassNames('height', height, isValidString),
generateClassNames('color', color, isValidString),
generateClassNames('background-color', backgroundColor, isValidString),
Expand Down
7 changes: 7 additions & 0 deletions ui/components/component-library/box/box.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export type StyleDeclarationType =
| 'align-items'
| 'text-align'
| 'width'
| 'min-width'
| 'height'
| 'color'
| 'background-color'
Expand Down Expand Up @@ -391,6 +392,12 @@ export interface StyleUtilityProps {
* Accepts responsive props in the form of an array.
*/
width?: BlockSize | BlockSizeArray;
/**
* The min-width of the component.
* Use BlockSize enum from '../../../helpers/constants/design-system';
* Accepts responsive props in the form of an array.
*/
minWidth?: BlockSize | BlockSizeArray;
/**
* The height of the component.
* Use BlockSize enum from '../../../helpers/constants/design-system';
Expand Down
1 change: 1 addition & 0 deletions ui/css/design-system/attributes.scss
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ $flex-direction: row, row-reverse, column, column-reverse;
$flex-wrap: wrap, wrap-reverse, nowrap;

$fractions: (
0: 0,
1\/2: 50%,
1\/3: 33.333333%,
2\/3: 66.666667%,
Expand Down
1 change: 1 addition & 0 deletions ui/helpers/constants/design-system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,7 @@ export const FRACTIONS = {
};

export enum BlockSize {
Zero = '0',
Half = '1/2',
OneThird = '1/3',
TwoThirds = '2/3',
Expand Down
Loading