generated from nl-design-system/example
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add subscript CSS and React component
- Loading branch information
Showing
19 changed files
with
341 additions
and
16 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 @@ | ||
--- | ||
"@utrecht/subscript-css": major | ||
--- | ||
|
||
Add Subscript CSS component. |
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 @@ | ||
--- | ||
"@utrecht/component-library-react": minor | ||
--- | ||
|
||
Add Subscript React component. |
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 @@ | ||
<!-- @license CC0-1.0 --> | ||
|
||
# Subscript | ||
|
||
Toont tekst met een kleiner lettertype onder de normale letterlijn. |
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,32 @@ | ||
{ | ||
"version": "0.0.0", | ||
"author": "Community for NL Design System", | ||
"description": "Subscript component for the Municipality of Utrecht based on the NL Design System architecture", | ||
"license": "EUPL-1.2", | ||
"name": "@utrecht/subscript-css", | ||
"files": [ | ||
"dist/", | ||
"docs/", | ||
"src/", | ||
"*.md" | ||
], | ||
"main": "dist/index.css", | ||
"scripts": { | ||
"build": "rollup -c ../rollup.config.mjs", | ||
"clean": "rimraf dist" | ||
}, | ||
"devDependencies": { | ||
"rollup": "4.18.0" | ||
}, | ||
"keywords": [ | ||
"nl-design-system" | ||
], | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"repository": { | ||
"type": "git+ssh", | ||
"url": "[email protected]:nl-design-system/utrecht.git", | ||
"directory": "components/subscript" | ||
} | ||
} |
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,17 @@ | ||
/** | ||
* @license EUPL-1.2 | ||
* Copyright (c) 2021 Robbert Broersma | ||
*/ | ||
|
||
/* stylelint-disable-next-line block-no-empty */ | ||
@mixin utrecht-subscript { | ||
} | ||
|
||
/* Not all fonts support the OpenType `subs` characters, and fonts that support it don't suppor all characters. | ||
* Use the optimized OpenType rendering only in situations where you know it will work. | ||
*/ | ||
@mixin utrecht-subscript--open-type { | ||
font-size: inherit; | ||
font-variant-position: sub; | ||
vertical-align: baseline; | ||
} |
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,12 @@ | ||
/** | ||
* @license EUPL-1.2 | ||
* Copyright (c) 2021 Robbert Broersma | ||
*/ | ||
|
||
@import "../mixin"; | ||
|
||
@mixin utrecht-html-sub { | ||
sub { | ||
@include utrecht-subscript; | ||
} | ||
} |
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,8 @@ | ||
/** | ||
* @license EUPL-1.2 | ||
* Copyright (c) 2021 Robbert Broersma | ||
*/ | ||
|
||
@import "./mixin"; | ||
|
||
@include utrecht-html-sub; |
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,14 @@ | ||
/** | ||
* @license EUPL-1.2 | ||
* Copyright (c) 2021 Robbert Broersma | ||
*/ | ||
|
||
@import "./mixin"; | ||
|
||
.utrecht-subscript { | ||
@include utrecht-subscript; | ||
} | ||
|
||
.utrecht-subscript--open-type { | ||
@include utrecht-subscript--open-type; | ||
} |
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 @@ | ||
{ | ||
"utrecht": { | ||
"subscript": {} | ||
} | ||
} |
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,29 @@ | ||
/** | ||
* @license EUPL-1.2 | ||
* Copyright (c) 2021 Gemeente Utrecht | ||
* Copyright (c) 2021 Robbert Broersma | ||
*/ | ||
|
||
import clsx from 'clsx'; | ||
import { ForwardedRef, forwardRef, HTMLAttributes, PropsWithChildren } from 'react'; | ||
|
||
export interface SubscriptProps extends HTMLAttributes<HTMLElement> { | ||
openType?: boolean; | ||
} | ||
|
||
export const Subscript = forwardRef( | ||
( | ||
{ children, className, openType, ...restProps }: PropsWithChildren<SubscriptProps>, | ||
ref: ForwardedRef<HTMLElement>, | ||
) => ( | ||
<sub | ||
ref={ref} | ||
className={clsx('utrecht-subscript', { 'utrecht-subscript--open-type': openType }, className)} | ||
{...restProps} | ||
> | ||
{children} | ||
</sub> | ||
), | ||
); | ||
|
||
Subscript.displayName = 'Subscript'; |
8 changes: 8 additions & 0 deletions
8
packages/component-library-react/src/css-module/Subscript.tsx
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,8 @@ | ||
/** | ||
* @license EUPL-1.2 | ||
* Copyright (c) 2021 Robbert Broersma | ||
*/ | ||
|
||
import '@utrecht/subscript-css/src/index.scss'; | ||
|
||
export * from '../Subscript'; |
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
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,103 @@ | ||
/* @license CC0-1.0 */ | ||
|
||
/* eslint-disable react/no-unescaped-entities */ | ||
|
||
import { Meta, StoryObj } from '@storybook/react'; | ||
import { Paragraph, Subscript } from '@utrecht/component-library-react/dist/css-module'; | ||
import tokens from '@utrecht/design-tokens/dist/index.json'; | ||
import readme from '@utrecht/subscript-css/README.md?raw'; | ||
import tokensDefinition from '@utrecht/subscript-css/src/tokens.json'; | ||
import React from 'react'; | ||
import { designTokenStory } from './design-token-story'; | ||
|
||
const meta = { | ||
title: 'CSS Component/Subscript', | ||
id: 'css-subscript', | ||
component: Subscript, | ||
argTypes: { | ||
children: { | ||
description: 'Tekst.', | ||
control: 'text', | ||
}, | ||
openType: { | ||
description: 'Render with OpenType font features.', | ||
control: 'boolean', | ||
}, | ||
}, | ||
args: { | ||
children: [], | ||
openType: false, | ||
}, | ||
parameters: { | ||
bugs: 'https://github.com/nl-design-system/utrecht/issues?q=is%3Aissue+is%3Aopen+label%3Acomponent%2Fsubscript', | ||
nldesignsystem: 'https://nldesignsystem.nl/subscript', | ||
tokensPrefix: 'utrecht-subscript', | ||
status: { | ||
type: 'ALPHA', | ||
}, | ||
tokens, | ||
tokensDefinition, | ||
docs: { | ||
description: { | ||
component: readme, | ||
}, | ||
}, | ||
decorators: [(Story: any) => <Paragraph>{Story()}</Paragraph>], | ||
}, | ||
} satisfies Meta<typeof Subscript>; | ||
|
||
export default meta; | ||
|
||
type Story = StoryObj<typeof meta>; | ||
|
||
export const Default: Story = { | ||
args: { | ||
children: 'The Quick Brown Fox Jumps Over The Lazy Dog', | ||
}, | ||
}; | ||
|
||
export const InsideText: Story = { | ||
args: { | ||
children: 'The Quick Brown Fox Jumps Over The Lazy Dog', | ||
}, | ||
name: 'Subscript inside multiple lines of text', | ||
parameters: { | ||
docs: { | ||
description: { | ||
story: `Subscript tekst kan de lijnhoogte verstoren, omdat er in sommige gevallen meer ruimte nodig is dan de ingestelde lijnhoogte.`, | ||
}, | ||
}, | ||
}, | ||
render: (props: any) => { | ||
return ( | ||
<> | ||
Its chemical formula, H<Subscript {...props}>2</Subscript>O, indicates that each of its molecules contains one | ||
oxygen and two hydrogen atoms, connected by covalent bonds. The hydrogen atoms are attached to the oxygen atom | ||
at an angle of 104.45°. In liquid form, H<Subscript {...props}>2</Subscript>O is also called "water" at standard | ||
temperature and pressure. | ||
</> | ||
); | ||
}, | ||
}; | ||
|
||
export const InsideTextOpenType: Story = { | ||
args: { | ||
children: 'The Quick Brown Fox Jumps Over The Lazy Dog', | ||
openType: true, | ||
}, | ||
name: 'Subscript with Open Type rendering, inside multiple lines of text', | ||
render: InsideText.render, | ||
parameters: { | ||
docs: { | ||
description: { | ||
story: `Experimental class name: \`utrecht-subscript--open-type\`. Apply this class name in specific situations, when it is certain the current font supports Open Type \`subs\` for all the characters inside the subscript text. | ||
To determine which characters are supported, you can upload your font to [Wakamai Fondue](https://wakamaifondue.com/) ("What can my font do?"), and scroll down to the \`subs\` section. When your font does not support \`subs\` then will be no such section. | ||
When you use this class with fonts that do not support this OpenType feature, subscript text will look the same as regular text, and the meaning of the text will become unclear.`, | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
export const DesignTokens = designTokenStory(meta); |
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
38 changes: 38 additions & 0 deletions
38
packages/storybook-react/src/stories/Subscript.stories.tsx
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,38 @@ | ||
import { Meta, StoryObj } from '@storybook/react'; | ||
import { Subscript } from '@utrecht/component-library-react/dist/css-module'; | ||
import tokens from '@utrecht/design-tokens/dist/index.json'; | ||
import readme from '@utrecht/subscript-css/README.md?raw'; | ||
import tokensDefinition from '@utrecht/subscript-css/src/tokens.json'; | ||
import { designTokenStory } from './util'; | ||
|
||
const meta = { | ||
title: 'React Component/Subscript', | ||
id: 'react-subscript', | ||
component: Subscript, | ||
args: { | ||
children: 'The Quick Brown Fox Jumps Over The Lazy Dog', | ||
}, | ||
argTypes: { | ||
openType: { | ||
description: 'Render with OpenType font features.', | ||
control: 'boolean', | ||
}, | ||
}, | ||
parameters: { | ||
tokensPrefix: 'utrecht-subscript', | ||
tokens, | ||
tokensDefinition, | ||
docs: { | ||
description: { | ||
component: readme, | ||
}, | ||
}, | ||
}, | ||
} satisfies Meta<typeof Subscript>; | ||
|
||
export default meta; | ||
|
||
type Story = StoryObj<typeof meta>; | ||
export const Default: Story = {}; | ||
|
||
export const DesignTokens = designTokenStory(meta); |
Oops, something went wrong.