Skip to content
Open
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
11 changes: 11 additions & 0 deletions .changeset/sunny-animals-leave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
'@guardian/stand': patch
---

BREAKING: Breakpoints have been simplified to `sm`, `md`, and `lg`

New breakpoint breakdown:

`sm` -> 0px - 599px
`md` -> 600px - 1023px
`lg` -> 1024px+
16 changes: 5 additions & 11 deletions src/styleD/build/css/semantic/breakpoints.css
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,9 @@

:root {
--semantic-breakpoints-sm-min: 0;
--semantic-breakpoints-sm-max: 671px;
--semantic-breakpoints-md-min: 672px;
--semantic-breakpoints-md-max: 1055px;
--semantic-breakpoints-lg-min: 1056px;
--semantic-breakpoints-lg-max: 1311px;
--semantic-breakpoints-xl-min: 1312px;
--semantic-breakpoints-xl-max: 1583px;
--semantic-breakpoints-max-min: 1584px;
--semantic-breakpoints-max-max: 1783px;
--semantic-breakpoints-maxplus-min: 1784px;
--semantic-breakpoints-maxplus-max: initial;
--semantic-breakpoints-sm-max: 599px;
--semantic-breakpoints-md-min: 600px;
--semantic-breakpoints-md-max: 1023px;
--semantic-breakpoints-lg-min: 1024px;
--semantic-breakpoints-lg-max: initial;
}
20 changes: 4 additions & 16 deletions src/styleD/build/typescript/semantic/breakpoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,14 @@
export const semanticBreakpoints = {
sm: {
min: '0',
max: '671px',
max: '599px',
},
md: {
min: '672px',
max: '1055px',
min: '600px',
max: '1023px',
},
lg: {
min: '1056px',
max: '1311px',
},
xl: {
min: '1312px',
max: '1583px',
},
max: {
min: '1584px',
max: '1783px',
},
maxplus: {
min: '1784px',
min: '1024px',
max: 'initial',
},
};
Expand Down
8 changes: 4 additions & 4 deletions src/styleD/stories/semantic/Breakpoints.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ import { between } from '@guardian/stand/utils';

const styles = css`
display: flex;
${between.md.and.xl} {
${between.sm.and.lg} {
flex-direction: column;
}
`;
Expand All @@ -111,11 +111,11 @@ import { semanticBreakpoints } from '@guardian/stand';
import '@guardian/stand/semantic/breakpoints.css'; // CSS custom properties

// JS/TS
const minWidth = semanticBreakpoints.md.min; // '672px'
const minWidth = semanticBreakpoints.md.min; // '600px'

// CSS custom properties
// var(--semantic-breakpoints-md-min) → 672px
// var(--semantic-breakpoints-md-max) → 1055px
// var(--semantic-breakpoints-md-min) → 600px
// var(--semantic-breakpoints-md-max) → 1023px
```

---
Expand Down
39 changes: 4 additions & 35 deletions src/styleD/stories/semantic/Breakpoints.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ const viewportWidthCss = css`
const parseMin = (value: string): number =>
value === '0' ? 0 : parseFloat(value);

const parseMax = (value: string | null): number =>
value === null ? Infinity : parseFloat(value);
const parseMax = (value: string): number =>
value === 'initial' ? Infinity : parseFloat(value);

const getActiveBreakpoint = (width: number): string | null => {
for (const [name, { min, max }] of Object.entries(semanticBreakpoints)) {
Expand Down Expand Up @@ -157,10 +157,6 @@ const fromGridCss = css`
${from.lg} {
grid-template-columns: repeat(3, 1fr);
}

${from.xl} {
grid-template-columns: repeat(6, 1fr);
}
`;

const fromCardCss = css`
Expand All @@ -175,9 +171,6 @@ const fromCardBreakpoints: Array<keyof typeof semanticBreakpoints> = [
'sm',
'md',
'lg',
'xl',
'max',
'maxplus',
];

/**
Expand All @@ -186,9 +179,7 @@ const fromCardBreakpoints: Array<keyof typeof semanticBreakpoints> = [
*/
export const FromDemo = () => (
<div css={demoWrapperCss}>
<span css={demoLabelCss}>
from.sm / from.md / from.lg / from.xl / from.max / from.maxplus
</span>
<span css={demoLabelCss}>from.sm / from.md / from.lg</span>
<div css={fromGridCss}>
{fromCardBreakpoints.map((bp) => {
const cardActiveCss = css`
Expand Down Expand Up @@ -238,7 +229,7 @@ const untilBoxBaseCss = css`
*/
export const UntilDemo = () => (
<div css={demoWrapperCss}>
<span css={demoLabelCss}>until.md / until.lg / until.xl</span>
<span css={demoLabelCss}>until.md / until.lg</span>
<div
css={css`
display: flex;
Expand Down Expand Up @@ -286,26 +277,6 @@ export const UntilDemo = () => (
above
</p>
</div>
<div
css={css`
${untilBoxBaseCss}
${until.xl} {
background: ${semanticColors.fill['accent-strong']};
border-color: ${semanticColors.fill['accent-strong']};
color: ${semanticColors.text['stronger-inverse']};

p {
color: ${semanticColors.text['stronger-inverse']};
}
}
`}
>
<p css={demoHeadingCss}>Visible below xl</p>
<p css={demoDescCss}>
<code>until.xl</code> - hidden at {semanticBreakpoints.xl.min} and
above
</p>
</div>
</div>
<p
css={css`
Expand All @@ -327,8 +298,6 @@ const betweenPairs: Array<{
}> = [
{ from: 'sm', to: 'md' },
{ from: 'md', to: 'lg' },
{ from: 'lg', to: 'xl' },
{ from: 'xl', to: 'max' },
];

/**
Expand Down
38 changes: 4 additions & 34 deletions src/styleD/tokens/foundations/local.json
Original file line number Diff line number Diff line change
Expand Up @@ -1531,53 +1531,23 @@
},
"max": {
"$type": "dimension",
"$value": "671px"
"$value": "599px"
}
},
"md": {
"min": {
"$type": "dimension",
"$value": "672px"
"$value": "600px"
},
"max": {
"$type": "dimension",
"$value": "1055px"
"$value": "1023px"
}
},
"lg": {
"min": {
"$type": "dimension",
"$value": "1056px"
},
"max": {
"$type": "dimension",
"$value": "1311px"
}
},
"xl": {
"min": {
"$type": "dimension",
"$value": "1312px"
},
"max": {
"$type": "dimension",
"$value": "1583px"
}
},
"max": {
"min": {
"$type": "dimension",
"$value": "1584px"
},
"max": {
"$type": "dimension",
"$value": "1783px"
}
},
"maxplus": {
"min": {
"$type": "dimension",
"$value": "1784px"
"$value": "1024px"
},
"max": {
"$type": "dimension",
Expand Down
33 changes: 17 additions & 16 deletions src/styleD/utils/semantic/mq.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,8 @@ describe('mq', () => {
describe('from', () => {
it('produces a min-width query for each breakpoint', () => {
expect(from.sm).toBe('@media (min-width: 0px)');
expect(from.md).toBe('@media (min-width: 672px)');
expect(from.lg).toBe('@media (min-width: 1056px)');
expect(from.xl).toBe('@media (min-width: 1312px)');
expect(from.max).toBe('@media (min-width: 1584px)');
expect(from.maxplus).toBe('@media (min-width: 1784px)');
expect(from.md).toBe('@media (min-width: 600px)');
expect(from.lg).toBe('@media (min-width: 1024px)');
});

it('has an entry for every breakpoint in semanticBreakpoints', () => {
Expand All @@ -21,11 +18,8 @@ describe('mq', () => {
describe('until', () => {
it('produces a max-width query 0.1px below the breakpoint min', () => {
expect(until.sm).toBe('@media (max-width: -0.1px)');
expect(until.md).toBe('@media (max-width: 671.9px)');
expect(until.lg).toBe('@media (max-width: 1055.9px)');
expect(until.xl).toBe('@media (max-width: 1311.9px)');
expect(until.max).toBe('@media (max-width: 1583.9px)');
expect(until.maxplus).toBe('@media (max-width: 1783.9px)');
expect(until.md).toBe('@media (max-width: 599.9px)');
expect(until.lg).toBe('@media (max-width: 1023.9px)');
});

it('has an entry for every breakpoint in semanticBreakpoints', () => {
Expand All @@ -44,16 +38,22 @@ describe('mq', () => {
describe('between', () => {
it('produces a min-width + max-width query for a range', () => {
expect(between.md.and.lg).toBe(
'@media (min-width: 672px) and (max-width: 1055.9px)',
'@media (min-width: 600px) and (max-width: 1023.9px)',
);
expect(between.sm.and.md).toBe(
'@media (min-width: 0px) and (max-width: 671.9px)',
'@media (min-width: 0px) and (max-width: 599.9px)',
);
expect(between.lg.and.xl).toBe(
'@media (min-width: 1056px) and (max-width: 1311.9px)',
});

it('produces a correct query for non-adjacent breakpoints', () => {
expect(between.sm.and.lg).toBe(
'@media (min-width: 0px) and (max-width: 1023.9px)',
);
expect(between.xl.and.max).toBe(
'@media (min-width: 1312px) and (max-width: 1583.9px)',
});

it('produces a correct query when lg is the lower bound', () => {
expect(between.lg.and.md).toBe(
'@media (min-width: 1024px) and (max-width: 599.9px)',
);
});

Expand All @@ -63,6 +63,7 @@ describe('mq', () => {
});

it('does not include a self-referencing entry in and', () => {
expect(between.sm.and).not.toHaveProperty('sm');
expect(between.md.and).not.toHaveProperty('md');
expect(between.lg.and).not.toHaveProperty('lg');
});
Expand Down
Loading