-
Notifications
You must be signed in to change notification settings - Fork 14
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
notlee
wants to merge
4
commits into
2025-release
Choose a base branch
from
2025-release-type-usecase-display
base: 2025-release
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
4907e2e
chore: Add token attributes to the tooling export
notlee e1ea571
chore: Add a utility class for display typography usecases
notlee 7ec5128
chore: Refactor the Preview component
notlee cf4b913
chore: Add display type usecase docs to the website
notlee File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
47 changes: 47 additions & 0 deletions
47
apps/for-everyone-website/src/components/TypeUsecase.astro
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,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); | ||
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> | ||
</>; | ||
}) | ||
} |
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
191 changes: 191 additions & 0 deletions
191
apps/for-everyone-website/src/components/utils/PreviewFrame.astro
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,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 */ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Who is brian? 🤔 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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> |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, thanks