Skip to content

Commit

Permalink
feat(typography): add @material/web/typography/md-typescale classes
Browse files Browse the repository at this point in the history
Fixes #1050

View the updated [typography docs](https://github.com/material-components/material-web/blob/main/docs/theming/typography.md#classes) for more info.

PiperOrigin-RevId: 613259080
  • Loading branch information
asyncLiz authored and copybara-github committed Mar 6, 2024
1 parent 758e615 commit 36dd77e
Show file tree
Hide file tree
Showing 7 changed files with 492 additions and 191 deletions.
34 changes: 19 additions & 15 deletions divider/demo/stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import '@material/web/divider/divider.js';

import {MaterialStoryInit} from './material-collection.js';
import {styles as typescaleStyles} from '@material/web/typography/md-typescale.js';
import {css, html} from 'lit';

/** Knob types for divider stories. */
Expand All @@ -18,25 +19,28 @@ export interface StoryKnobs {

const standard: MaterialStoryInit<StoryKnobs> = {
name: 'Divider',
styles: css`
ul {
border: 1px solid var(--md-sys-color-outline);
margin: 0;
padding: 0;
width: 256px;
}
styles: [
typescaleStyles,
css`
ul {
border: 1px solid var(--md-sys-color-outline);
margin: 0;
padding: 0;
width: 256px;
}
li {
color: var(--md-sys-color-on-background);
font-family: system-ui;
list-style: none;
margin: 16px;
}
`,
li {
color: var(--md-sys-color-on-background);
list-style: none;
margin: 16px;
}
`,
],
render(knobs) {
return html`
<ul
aria-label="A list of items with decorative and non-decorative separators">
aria-label="A list of items with decorative and non-decorative separators"
class="md-typescale-body-medium">
<li>List item one</li>
<md-divider
?inset=${knobs.inset}
Expand Down
32 changes: 31 additions & 1 deletion docs/theming/typography.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ order: 3

<!--*
# Document freshness: For more information, see go/fresh-source.
freshness: { owner: 'lizmitchell' reviewed: '2023-09-06' }
freshness: { owner: 'lizmitchell' reviewed: '2024-03-05' }
tag: 'docType:howTo'
*-->

Expand Down Expand Up @@ -71,6 +71,36 @@ A
is a collection of font styles: `font-family`, `font-size`, `line-height`, and
`font-weight`.

### Classes

<!-- go/md-typescale -->

Typescales can be applied to an element using the classes from the typescale
stylesheet.

Class names follow the naming convention `.md-typescale-<scale>-<size>`.

```ts
import {styles as typescaleStyles} from '@material/web/typography/md-typescale.js';

// `typescaleStyles.styleSheet` is a `CSSStyleSheet` that can be added to a
// document or shadow root's `adoptedStyleSheets` to use the `.md-typescale-*`
// classes.
document.adoptedStyleSheets.push(typescaleStyles.styleSheet);

// `typescaleStyles` can also be added to a `LitElement` component's styles.
class App extends LitElement {
static styles = [typescaleStyles, css`...`];

render() {
return html`
<h1 class="md-typescale-display-large">Large display</h1>
<p class="md-typescale-body-medium">Body text</p>
`;
}
}
```

### Tokens

Typescales can be set using
Expand Down
42 changes: 21 additions & 21 deletions iconbutton/demo/stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import '@material/web/iconbutton/icon-button.js';
import '@material/web/iconbutton/outlined-icon-button.js';

import {MaterialStoryInit} from './material-collection.js';
import {styles as typescaleStyles} from '@material/web/typography/md-typescale.js';
import {css, html} from 'lit';

/** Knob types for icon button stories. */
Expand All @@ -20,33 +21,32 @@ export interface StoryKnobs {
disabled: boolean;
}

const styles = css`
.column {
display: flex;
flex-direction: column;
align-items: center;
}
.row {
display: flex;
gap: 32px;
}
p {
color: var(--md-sys-color-on-surface);
font: var(--md-sys-typescale-body-medium-weight, 400)
var(--md-sys-typescale-body-medium-size, 0.875rem) /
var(--md-sys-typescale-body-medium-line-height, 1.25rem)
var(--md-sys-typescale-body-medium-font, 'Roboto');
}
`;
const styles = [
typescaleStyles,
css`
.column {
display: flex;
flex-direction: column;
align-items: center;
}
.row {
display: flex;
gap: 32px;
}
p {
color: var(--md-sys-color-on-surface);
}
`,
];

const buttons: MaterialStoryInit<StoryKnobs> = {
name: 'Icon button variants',
styles,
render({icon, disabled}) {
return html`
<div class="row">
<div class="row md-typescale-body-medium">
<div class="column">
<p>Standard</p>
<md-icon-button aria-label="Open settings" ?disabled=${disabled}>
Expand Down
62 changes: 31 additions & 31 deletions labs/card/demo/stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import '@material/web/labs/card/filled-card.js';
import '@material/web/labs/card/outlined-card.js';

import {MaterialStoryInit} from './material-collection.js';
import {styles as typescaleStyles} from '@material/web/typography/md-typescale.js';
import {css, html} from 'lit';

/** Knob types for card stories. */
Expand All @@ -18,45 +19,44 @@ export interface StoryKnobs {}
const MEDIA_IMAGE =
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAALwAAAC8CAYAAADCScSrAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAlHSURBVHgB7d0HbxtHFsDxJ1Hdala15CaXxL44TmLg7vt/gQNyJbmzZUqkOtVFFVLd4dsUO4oKy+7szL7/DzCSAEESI3+uZme5b9pm88VPAhjRLoAhBA9TCB6mEDxMIXiYQvAwheBhCsHDFIKHKQQPUwgephA8TCF4mELwMIXgYQrBwxSChykED1MIHqYQPEwheJhC8DCF4GEKwcMUgocpBA9TCB6mEDxM6RA4sb6xKYdHRzI+NiqDAwOCdBC8A6trJZmdm4/+fKX25/9494P09vYI3GNJk7DT0zMpLi398deXl5eSLxQE6SD4hBUXF6Pov7S9sys7u7sC9wg+QbpmL9XW7tfJzxfl0yfOonCN4BOUny9ES5jrVKpVWV5dFbhF8AnZ2NySvfL+rX/PwtJybblzKnCH4BOgV/W5QvHOv+/8/ELmi4sCdwg+AXrlPqnzyl3a2JD9gwOBGwQfs+PjE1laaWxtrmt9bmDdIPiY6R77TTeqN9k/OIyu9EgewcdI99a3tnekGYWFxdqa/lyQLIKPiV7VW7kB1YdTuvZHsgg+Jqul9ehBUyuWV9ekUqkKkkPwMdCrsy5JWqU3rh/n5wXJIfgYFBYW5OLiQuKwu1eu3QdsC5JB8C3SZczaerw7LHOFhYZ3elAfgm/R+9m8xK16fCyLyyuC+BF8C0q1K3urN6o30eBPTvieTdwIvknRNmRt7Z7oP7+Y3D/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2Eid3633Dw6kpGR8bdfqqXrMI3gi9ym9sbkVnRekhBK1c9fWnnAau++quX+BoFcEbpLMcy/sHtV+/Hh1ZqVTl5PT02g+BDoHSp6N9fX0yONBfu6IPyr2+cKcoEDz+oB+Ei4vL6JACvTnXERohLFMake0ZbmiIBp71OZY8eIIpBA9TCB6mEDxMIXiYQvAwheBhCsHDFIKHKQQPUwgephA8TCF4mELwMIXgYQrBwxSChykED1MIHqYQPEwheJhC8DCF4GEKwcMUgocpBA9TfgF+si70ZYTauwAAAABJRU5ErkJggg==';

const styles = css`
.container {
display: flex;
flex-wrap: wrap;
gap: 8px;
color: var(--md-sys-color-on-surface);
font: var(--md-sys-typescale-body-medium-weight, 400)
var(--md-sys-typescale-body-medium-size, 0.875rem) /
var(--md-sys-typescale-body-medium-line-height, 1.25rem)
var(--md-sys-typescale-body-medium-font, 'Roboto');
}
const styles = [
typescaleStyles,
css`
.container {
display: flex;
flex-wrap: wrap;
gap: 8px;
color: var(--md-sys-color-on-surface);
}
.card {
width: 192px;
}
.card {
width: 192px;
}
img {
border-radius: inherit;
background: #dadce0;
object-fit: contain;
height: 128px;
}
img {
border-radius: inherit;
background: #dadce0;
object-fit: contain;
height: 128px;
}
.content {
display: flex;
flex-direction: column;
flex: 1;
justify-content: space-between;
padding: 16px;
gap: 16px;
}
`;
.content {
display: flex;
flex-direction: column;
flex: 1;
justify-content: space-between;
padding: 16px;
gap: 16px;
}
`,
];

const cards: MaterialStoryInit<StoryKnobs> = {
name: 'Cards',
styles,
render() {
return html`
<div class="container">
<div class="container md-typescale-body-medium">
<md-elevated-card class="card">
<img src=${MEDIA_IMAGE} alt="Placeholder image" />
<div class="content">A static elevated card</div>
Expand All @@ -81,7 +81,7 @@ const withActions: MaterialStoryInit<StoryKnobs> = {
styles,
render() {
return html`
<div class="container">
<div class="container md-typescale-body-medium">
<md-elevated-card class="card">
<img src=${MEDIA_IMAGE} alt="Placeholder image" />
<div class="content">
Expand Down
Loading

0 comments on commit 36dd77e

Please sign in to comment.