-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Add breakpoint tokens for mediaQueries * Add initial type def for mediaQueries * Make corrections in docs * Follow file naming convention * Use relative import for type def * Export breakpoints, pureWidths * Use singular variables and object structure * Use CSS-in-JS syntax in docs * Update type definition * Update comments * Add docs comments * Update docs comment with usage * Add unit to docs column label Co-authored-by: Bea Esguerra <[email protected]> --------- Co-authored-by: Bea Esguerra <[email protected]>
- Loading branch information
1 parent
1e2d70b
commit 6999fd3
Showing
6 changed files
with
173 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@khanacademy/wonder-blocks-tokens": minor | ||
--- | ||
|
||
Add mediaQuery tokens for viewport sizing |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import {Meta, Source} from "@storybook/blocks"; | ||
|
||
import TokenTable from "../../.storybook/components/token-table"; | ||
|
||
import {View} from "@khanacademy/wonder-blocks-core"; | ||
import * as tokens from "@khanacademy/wonder-blocks-tokens"; | ||
|
||
import ComponentInfo from "../../.storybook/components/component-info"; | ||
import packageConfig from "../../packages/wonder-blocks-tokens/package.json"; | ||
|
||
<Meta title="Packages / Tokens / Media Query Breakpoints" /> | ||
|
||
# Media Queries | ||
|
||
<ComponentInfo name={packageConfig.name} version={packageConfig.version} /> | ||
|
||
All the available media query breakpoint values and pure widths that can be used for min-width, | ||
max-width, width, etc. | ||
|
||
## Usage | ||
|
||
### Media Queries | ||
|
||
You can use mediaQuery conditions by importing `breakpoint` from the | ||
`wonder-blocks-tokens` package and accessing its object properties for sizing like so: | ||
`breakpoint.mediaQuery.sm`. | ||
|
||
```js | ||
import {breakpoint} from "@khanacademy/wonder-blocks-tokens"; | ||
const styles = { | ||
[breakpoint.mediaQuery.sm]: { | ||
flexDirection: "column" | ||
} | ||
}; | ||
``` | ||
|
||
### Pure widths | ||
|
||
You can also use pure width values by importing `breakpoint` from the | ||
`wonder-blocks-tokens` package and accessing the `width` object: | ||
`breakpoint.width.sm`. These can be useful for tooling or in CSS where a number value | ||
is needed. Therefore, pixel values are returned without a unit. You can interpolate | ||
a string to add the `px` unit like so: | ||
|
||
```js | ||
import {breakpoint} from "@khanacademy/wonder-blocks-tokens"; | ||
const styles = { | ||
element: { | ||
maxWidth: `${breakpoint.width.lg}px` | ||
} | ||
}; | ||
``` | ||
|
||
## Tokens | ||
|
||
<TokenTable | ||
columns={[ | ||
{ | ||
label: "Media Query Token", | ||
cell: (row) => <code>breakpoint.mediaQuery.{row.label}</code>, | ||
}, | ||
{ | ||
label: "Value", | ||
cell: "value", | ||
}, | ||
]} | ||
tokens={tokens.breakpoint.mediaQuery} | ||
/> | ||
|
||
<TokenTable | ||
columns={[ | ||
{ | ||
label: "Width Token", | ||
cell: (row) => <code>breakpoint.width.{row.label}</code>, | ||
}, | ||
{ | ||
label: "Value (px)", | ||
cell: "value", | ||
}, | ||
]} | ||
tokens={tokens.breakpoint.width} | ||
/> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/** | ||
* A default set of media queries to use for different screen sizes. | ||
* | ||
* Breakpoint documentation: https://khanacademy.atlassian.net/wiki/spaces/WB/pages/2099970518/Layout+Breakpoints | ||
* | ||
*/ | ||
|
||
/* Pure width values */ | ||
const width = { | ||
xsMax: 567, | ||
smMin: 568, | ||
smMax: 681, | ||
mdMin: 682, | ||
mdMax: 1023, | ||
lgMin: 1024, | ||
} as const; | ||
|
||
/* Named mediaQuery conditions */ | ||
const mediaQuery = { | ||
// Note: any updates to this will need to be replicated in /types/aphrodite.d.ts | ||
xs: `@media screen and (max-width: ${width.xsMax}px) /* breakpoint.mediaQuery.xs */`, | ||
sm: `@media screen and (min-width: ${width.smMin}px) and (max-width: ${width.smMax}px) /* breakpoint.mediaQuery.sm */`, | ||
md: `@media screen and (min-width: ${width.mdMin}px) and (max-width: ${width.mdMax}px) /* breakpoint.mediaQuery.md */`, | ||
lg: `@media screen and (min-width: ${width.mdMin}px) and (max-width: ${width.lgMin}px) /* breakpoint.mediaQuery.lg */`, | ||
xl: `@media screen and (min-width: ${width.lgMin}px) /* breakpoint.mediaQuery.xl */`, | ||
|
||
xsOrSmaller: `@media screen and (max-width: ${width.xsMax}px) /* breakpoint.mediaQuery.xsOrSmaller */`, | ||
smOrSmaller: `@media screen and (max-width: ${width.smMax}px) /* breakpoint.mediaQuery.smOrSmaller */`, | ||
mdOrSmaller: `@media screen and (max-width: ${width.mdMax}px) /* breakpoint.mediaQuery.mdOrSmaller */`, | ||
lgOrSmaller: `@media screen and (max-width: ${width.lgMin}px) /* breakpoint.mediaQuery.lgOrSmaller */`, | ||
|
||
smOrLarger: `@media screen and (min-width: ${width.smMin}px) /* breakpoint.mediaQuery.smOrLarger */`, | ||
mdOrLarger: `@media screen and (min-width: ${width.mdMin}px) /* breakpoint.mediaQuery.mdOrLarger */`, | ||
lgOrLarger: `@media screen and (min-width: ${width.lgMin}px) /* breakpoint.mediaQuery.lgOrLarger */`, | ||
} as const; | ||
|
||
export const breakpoint = { | ||
width, | ||
mediaQuery, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters