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 examples of headings with icons #420

Merged
merged 2 commits into from
Aug 30, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
32 changes: 32 additions & 0 deletions storybook/stories/_docs/foundation_typography.stories.mdx
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import { Meta, Story, Canvas } from '@storybook/addon-docs'

import { IconLocationTemplate } from '../components/Icons/IconLocation'

export const testHeadingIcon = IconLocationTemplate({
customClass: 'inline',
})

<Meta title="Foundation/Typography" parameters={{ viewMode: 'docs' }} />

# Typography
Expand Down Expand Up @@ -195,6 +201,32 @@ Note:
</Story>
</Canvas>

## Headings Icons
thibaudcolas marked this conversation as resolved.
Show resolved Hide resolved

We can also add icons next to the headings.

<Canvas>
<Story name="Heading Icons">
{`
<div>
<p class="text-h1-alt mt-8">${testHeadingIcon}Header H1 Alt</p>
<code>.text-h1-alt</code>
<p class="text-h1 mt-8">${testHeadingIcon}Header H1</p>
<code>h1, .text-h1</code>
<p class="text-h2 mt-8">${testHeadingIcon}Header H2</p>
<code>h2, .text-h2</code>
<p class="text-h3 mt-8">${testHeadingIcon}Header H3</p>
<code>h3, .text-h3</code>
<p class="text-h4 mt-8">${testHeadingIcon}Header H4</p>
<code>h4, .text-h4</code>
<p class="text-h5 mt-8">${testHeadingIcon}Header H5</p>
<code>h5, .text-h5</code>
<p class="text-h6 mt-8">${testHeadingIcon}Header H6</p>
<code>h6, .text-h6</code>
`}
</Story>
</Canvas>

## Text Contrast

In areas where text overlays an image, use this `.text-contrast` class in conjunction with a semi-transparent overlay (ex. `bg-black bg-opacity-*`) to improve readability. `.text-contrast` also works with tailwind breakpoints.
Expand Down
13 changes: 11 additions & 2 deletions storybook/stories/components/BaseHeading/BaseHeading.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
export const BaseHeadingTemplate = ({ text, size, tag, headingClass }) => {
export const BaseHeadingTemplate = ({
text,
size,
tag,
icon = '',
headingClass,
}) => {
let computedClass = headingClass ? headingClass + ' ' : ''
if (!size) size = 'h3' // default
if (!tag) tag = size
Expand All @@ -12,5 +18,8 @@ export const BaseHeadingTemplate = ({ text, size, tag, headingClass }) => {
}
computedClass += sizes[size]

return `<${tag} class="${computedClass}">${text}</${tag}>`
// Use a space between the icon and text so its size is proportional to the font size.
const iconWrapper = icon ? `${icon} ` : ''

return `<${tag} class="${computedClass}">${iconWrapper}${text}</${tag}>`
}
27 changes: 27 additions & 0 deletions storybook/stories/components/BaseHeading/BaseHeading.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ import {
} from '@storybook/addon-docs'
import { BaseHeadingTemplate } from './BaseHeading'

import { IconLocationTemplate } from '../Icons/IconLocation'
import { IconArrowsTemplate } from '../Icons/IconArrows'
import { IconUserTemplate } from '../Icons/IconUser'

export default {
title: 'Components/Base/BaseHeading',
argTypes: {
Expand Down Expand Up @@ -59,19 +63,42 @@ export default {
}

export const H1 = BaseHeadingTemplate.bind({})
H1.storyName = 'H1'
H1.args = { text: 'Heading 1', size: 'h1', tag: 'h1' }

export const H2 = BaseHeadingTemplate.bind({})
H2.storyName = 'H2'
H2.args = { text: 'Heading 2', size: 'h2', tag: 'h2' }

export const H3 = BaseHeadingTemplate.bind({})
H3.storyName = 'H3'
H3.args = { text: 'Heading 3', size: 'h3', tag: 'h3' }

export const H4 = BaseHeadingTemplate.bind({})
H4.storyName = 'H4'
H4.args = { text: 'Heading 4', size: 'h4', tag: 'h4' }

export const H5 = BaseHeadingTemplate.bind({})
H5.storyName = 'H5'
H5.args = { text: 'Heading 5', size: 'h5', tag: 'h5' }

export const H6 = BaseHeadingTemplate.bind({})
H6.storyName = 'H6'
H6.args = { text: 'Heading 6', size: 'h6', tag: 'h6' }

export const HeadingsWithIcons = ((args) => {
const iconProps = { customClass: 'inline' }

// Test with icons of different shapes.
return `
${BaseHeadingTemplate({ ...args, icon: IconLocationTemplate(iconProps) })}
${BaseHeadingTemplate({ ...args, icon: IconUserTemplate(iconProps) })}
${BaseHeadingTemplate({ ...args, icon: IconArrowsTemplate(iconProps) })}
`
}).bind({})
HeadingsWithIcons.args = {
text: 'Heading 3',
size: 'h3',
tag: 'h3',
headingClass: 'mt-8',
}
Loading