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 display typography styles [OR-1205] #1919

Open
wants to merge 4 commits into
base: 2025-release
Choose a base branch
from
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
5 changes: 5 additions & 0 deletions apps/dictionary/src/formatters/js/tooling.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ const toolingFormat = ({dictionary}) => {
originalValue: token.original.value,
type,
description: token.description,
attributes: {
item: token.attributes.item,
subitem: token.attributes.subitem,
state: token.attributes.state,
},
origamiKeys: token.origamiKeys,
path: token.path,
origamiTint: token.origamiTint,
Expand Down
2 changes: 1 addition & 1 deletion apps/for-everyone-website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"@financial-times/o3-editorial-typography": "^2.0.0",
"@financial-times/o3-figma-sb-links": "^0.0.0",
"@financial-times/o3-form": "^0.5.0",
"@financial-times/o3-foundation": "^2.0.0",
"@financial-times/o3-foundation": "^2.3.1",
"@financial-times/o3-social-sign-in": "^1.0.0",
"@financial-times/o3-tooling-token": "^0.0.0",
"@financial-times/o3-tooltip": "^2.0.0",
Expand Down
47 changes: 47 additions & 0 deletions apps/for-everyone-website/src/components/TypeUsecase.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
---
import PreviewFrame from './utils/PreviewFrame.astro';

const tokens = await import(`@financial-times/o3-tooling-token/${Astro.props.brand}.js`);

const usecases = Array.isArray(Astro.props.usecases) ? Astro.props.usecases : [Astro.props.usecases];

const TypeUsecaseTokens = Object.entries(tokens.default).filter(([key, value]) => key.includes(`o3-typography-use-case`) && usecases.includes(value.attributes?.subitem)).map(([key, value]) => {
value.name = key;
return value
});
const TypeUsecaseTokensByItem = Object.groupBy(TypeUsecaseTokens, (token) => token.attributes?.subitem);

---

{


Object.entries(TypeUsecaseTokensByItem).map(([key, tokens]) => {
console.log(tokens);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, thanks

return <>
<h3>{key}</h3>
<p>{tokens[0].description}</p>

<PreviewFrame html={`<span class="o3-typography-use-case-${key}">Make sense of all of it</span>`} mark={`class="o3-typography-use-case-${key}`} />

<table class="color-table">
<thead>
<tr>
<th>Name</th>
<th>CSS Custom Property</th>
<th>Value</th>
</tr>
</thead>
<tbody>
{tokens.map(token => {
return <tr>
<td>{token.type}</td>
<td>{token.css}</td>
<td>{token.value}</td>
</tr>
})}
</tbody>
</table>
</>;
})
}
41 changes: 2 additions & 39 deletions apps/for-everyone-website/src/components/utils/Preview.astro
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {resolve as pathResolve} from 'path';
import {readFile} from 'node:fs/promises';
import {format} from 'prettier';
import {renderToString} from 'react-dom/server';
import {Tabs, TabItem, Code} from '@astrojs/starlight/components';
import PreviewFrame from './PreviewFrame.astro';

const {component} = Astro.props;
const mark = component?.previewMarkers?.mark;
Expand Down Expand Up @@ -35,46 +35,9 @@ const componentHTML =
parser: 'html',
htmlWhitespaceSensitivity: 'ignore',
}));

const uniqueID = 'switcher-' + Math.random().toString(36).substring(7);
---

<div class="not-content">
<div class="slide-switch">
<label class="switch-label" for={uniqueID}>Show code</label>
<label class="switch">
<input class="sliding-switch" id={uniqueID} type="checkbox" />
<span class="slider round"></span>
</label>
</div>

<div class="component-preview-wrapper">
<div class={`not-content component-preview visible ${uniqueID}`}>
<component.preview />
</div>
</div>

<div class={`code-preview ${uniqueID}`}>
<div>
<Tabs syncKey="code">
{
componentJSX && (
<TabItem label="JSX">
<Code code={componentJSX} lang="jsx" wrap={true} {mark} />
</TabItem>
)
}
{
componentHTML && (
<TabItem label="HTML">
<Code code={componentHTML} lang="html" wrap={true} {mark} />
</TabItem>
)
}
</Tabs>
</div>
</div>
</div>
<PreviewFrame html={componentHTML} jsx={componentJSX} component={component.preview} {mark} />

<script>
const checkBoxElelements = document.querySelectorAll('.sliding-switch');
Expand Down
191 changes: 191 additions & 0 deletions apps/for-everyone-website/src/components/utils/PreviewFrame.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
---
import {Tabs, TabItem, Code} from '@astrojs/starlight/components';

const {component: Component, html, jsx, mark} = Astro.props;
const uniqueID = 'switcher-' + Math.random().toString(36).substring(7);
---

<div class="not-content">
<div class="slide-switch">
<label class="switch-label" for={uniqueID}>Show code</label>
<label class="switch">
<input class="sliding-switch" id={uniqueID} type="checkbox" />
<span class="slider round"></span>
</label>
</div>

<div class="component-preview-wrapper">
<div class={`not-content component-preview visible ${uniqueID}`}>
{Component ? <Component /> : <Fragment set:html={html} />}
</div>
</div>

<div class={`code-preview ${uniqueID}`}>
<div>
<Tabs syncKey="code">
{
jsx && (
<TabItem label="JSX">
<Code code={jsx} lang="jsx" wrap={true} {mark} />
</TabItem>
)
}
{
html && (
<TabItem label="HTML">
<Code code={html} lang="html" wrap={true} {mark} />
</TabItem>
)
}
</Tabs>
</div>
</div>
</div>

<script>
const checkBoxElelements = document.querySelectorAll('.sliding-switch');
checkBoxElelements.forEach(el => {
el.addEventListener('change', () => {
const elId = el.id;
const componentPreveiw = document.querySelector(
`.component-preview.${elId}`
);
const codePreview = document.querySelector(`.code-preview.${elId}`);
if ((el as HTMLInputElement).checked) {
componentPreveiw?.classList.remove('visible');
codePreview?.classList.add('visible');
} else {
codePreview?.classList.remove('visible');
componentPreveiw?.classList.add('visible');
}
});
});
</script>

<style>
/* The switch - the box around the slider */
.switch {
position: relative;
display: inline-block;
width: 36px;
height: 20px;
}

/* Hide default HTML checkbox BUT KEEP OUTLINE WHEN SELECTED WITH TAB KEY! */
.switch input {
width: 36px;
height: 22px;
appearance: none;
-moz-appearance: none;
-webkit-appearance: none;
vertical-align: text-bottom;
}

/* HIDE THE CHECKBOX COMPLETELY ON IOS */
@supports (-webkit-touch-callout: none) {
.switch input {
opacity: 0;
}
}

/* The slider */
.slider {
position: absolute;
cursor: pointer;
top: 0;
left: 0;
right: 0;
bottom: 0;
width: 36px;
background-color: #ccc;
-webkit-transition: 0.4s;
transition: 0.4s;
}

.slider:before {
position: absolute;
content: '';
height: 16px;
width: 16px;
left: 2px;
bottom: 2px;
background-color: white;
-webkit-transition: 0.4s;
transition: 0.4s;
}

input:checked + .slider {
background-color: var(--o3-color-palette-teal);
}

input:focus + .slider {
box-shadow: 0 0 1px var(--o3-color-palette-teal);
}

input:checked + .slider:before {
-webkit-transform: translateX(16px);
-ms-transform: translateX(16px);
transform: translateX(16px);
}

/* Rounded sliders */
.slider.round {
border-radius: 16px;
}

.slider.round:before {
border-radius: 50%;
}

/* LABEL ADDED BY BRIAN */
Copy link
Contributor

@frshwtr frshwtr Jan 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Who is brian? 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have no idea 🤔 This was authored by Ako so we'll never know 🎻

.switch-label {
display: inline;
font-size: 14px;
font-weight: 500;
padding-right: 8px;
vertical-align: top;
}
.slide-switch {
display: flex;
align-items: center;
justify-content: flex-end;
white-space: nowrap;
margin-right: 40px;
}

.code-preview,
.component-preview {
display: none;
}

.code-preview {
padding: 0.5rem;
width: 100%;
}

.code-preview > div {
flex-grow: 1;
}

.component-preview-wrapper {
}

.component-preview {
padding: 4rem;
gap: 1rem;
justify-content: var(--preview-justify, center);
align-items: center;
background-image: url('/assets/images/utils/dot.svg');
background-repeat: repeat;
background-size: 1.5rem;
background-color: var(--o3-color-use-case-page-background);
margin: 0.5rem;
resize: both;
border-radius: 0.33rem;
border: 1px solid var(--o3-color-palette-black-40);
}

.visible {
display: var(--preview-display, flex);
}
</style>
Loading
Loading