Skip to content

Migrate Heading to TypeScript #975

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

Merged
merged 7 commits into from
Jan 25, 2021
Merged
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 .changeset/fluffy-peaches-study.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@primer/components": patch
---

Migrate `Heading` to TypeScript
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"@styled-system/props": "5.1.4",
"@styled-system/theme-get": "5.1.2",
"@types/styled-components": "^4.4.0",
"@types/styled-system": "5.1.2",
"@types/styled-system": "5.1.10",
"@types/styled-system__css": "5.0.14",
"@types/styled-system__theme-get": "5.0.1",
"classnames": "^2.2.5",
Expand Down
7 changes: 4 additions & 3 deletions src/Heading.js → src/Heading.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import styled from 'styled-components'
import sx from './sx'
import sx, {SxProp} from './sx'
import PropTypes from 'prop-types'
import {TYPOGRAPHY, COMMON, get} from './constants'
import {TYPOGRAPHY, COMMON, get, SystemTypographyProps, SystemCommonProps} from './constants'
import theme from './theme'

const Heading = styled.h2`
const Heading = styled.h2<SystemTypographyProps & SystemCommonProps & SxProp>`
font-weight: ${get('fontWeights.bold')};
font-size: ${get('fontSizes.5')};
margin: 0;
Expand All @@ -24,4 +24,5 @@ Heading.propTypes = {
...TYPOGRAPHY.propTypes
}

export type HeadingProps = React.ComponentProps<typeof Heading>
export default Heading
25 changes: 0 additions & 25 deletions src/__tests__/Heading.js → src/__tests__/Heading.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,6 @@ describe('Heading', () => {
expect(render(<Heading fontFamily="mono" theme={theme} />)).toHaveStyleRule('font-family', theme.fonts.mono)
})

it.skip('respects nowrap', () => {
expect(render(<Heading nowrap theme={theme} />)).toEqual(render(<span className="no-wrap" />))
})

it('renders fontSize', () => {
for (const fontSize of theme.fontSizes) {
expect(render(<Heading fontSize={fontSize} theme={theme} />)).toHaveStyleRule('font-size', `${fontSize}`)
Expand All @@ -93,25 +89,4 @@ describe('Heading', () => {
it('respects the "fontStyle" prop', () => {
expect(render(<Heading fontStyle="italic" />)).toHaveStyleRule('font-style', 'italic')
})

it.skip('renders fontSize with f* classes using inverse scale', () => {
expect(render(<Heading fontSize={0} theme={theme} />)).toEqual(render(<span className="f6" />))
expect(render(<Heading fontSize={1} theme={theme} />)).toEqual(render(<span className="f5" />))
expect(render(<Heading fontSize={2} theme={theme} />)).toEqual(render(<span className="f4" />))
expect(render(<Heading fontSize={3} theme={theme} />)).toEqual(render(<span className="f3" />))
expect(render(<Heading fontSize={4} theme={theme} />)).toEqual(render(<span className="f2" />))
expect(render(<Heading fontSize={5} theme={theme} />)).toEqual(render(<span className="f1" />))
expect(render(<Heading fontSize={6} theme={theme} />)).toEqual(render(<span className="f0" />))
})

it.skip('does not pass on arbitrary attributes', () => {
const defaultOutput = render(<Heading />)
expect(render(<Heading bugs="bar" />)).toEqual(defaultOutput)
expect(render(<Heading hidden />)).toEqual(defaultOutput)
})

it.skip('respects other values for fontSize', () => {
expect(render(<Heading fontSize="2em" theme={theme} />)).toHaveStyleRule('font-size', '2em')
expect(render(<Heading fontSize={100} theme={theme} />)).toHaveStyleRule('font-size', '100px')
})
})
60 changes: 30 additions & 30 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1882,9 +1882,9 @@
integrity sha512-cpmwBRcHJmmZx0OGU7aPVwGWGbs4iKwVYchk9iuMtxNCA2zorwdaTz4GkLgs2WGxiRZRFKnV1k6tRUHX7tBMxg==

"@types/json-schema@^7.0.3", "@types/json-schema@^7.0.5":
version "7.0.6"
resolved "https://registry.yarnpkg.com/@types/json-schema/-/json-schema-7.0.6.tgz#f4c7ec43e81b319a9815115031709f26987891f0"
integrity sha512-3c+yGKvVP5Y9TYBEibGNR+kLtijnj7mYrXRg+WpFb2X9xm04g/DXYkfg4hmzJQosc9snFNUPkbYIhu+KAm6jJw==
version "7.0.7"
resolved "https://registry.yarnpkg.com/@types/json-schema/-/json-schema-7.0.7.tgz#98a993516c859eb0d5c4c8f098317a9ea68db9ad"
integrity sha512-cxWFQVseBm6O9Gbw1IWb8r6OS4OhSt3hPZLkFApLjM8TEXROBuQGLAH2i2gZpcXdLBIrpXuTDhH7Vbm1iXmNGA==

"@types/json5@^0.0.29":
version "0.0.29"
Expand Down Expand Up @@ -1912,14 +1912,14 @@
integrity sha512-fZQQafSREFyuZcdWFAExYjBiCL7AUCdgsk80iO0q4yihYYdcIiH28CcuPTGFgLOCC8RlW49GSQxdHwZP+I7CNg==

"@types/node@*":
version "14.14.21"
resolved "https://registry.yarnpkg.com/@types/node/-/node-14.14.21.tgz#d934aacc22424fe9622ebf6857370c052eae464e"
integrity sha512-cHYfKsnwllYhjOzuC5q1VpguABBeecUp24yFluHpn/BQaVxB1CuQ1FSRZCzrPxrkIfWISXV2LbeoBthLWg0+0A==
version "14.14.22"
resolved "https://registry.yarnpkg.com/@types/node/-/node-14.14.22.tgz#0d29f382472c4ccf3bd96ff0ce47daf5b7b84b18"
integrity sha512-g+f/qj/cNcqKkc3tFqlXOYjrmZA+jNBiDzbP3kH+B+otKFqAdPgVTGP1IeKRdMml/aE69as5S4FqtxAbl+LaMw==

"@types/node@^12.7.1":
version "12.19.14"
resolved "https://registry.yarnpkg.com/@types/node/-/node-12.19.14.tgz#59e5029a3c2aea34f68b717955381692fd47cafb"
integrity sha512-2U9uLN46+7dv9PiS8VQJcHhuoOjiDPZOLAt0WuA1EanEknIMae+2QbMhayF7cgGqjvRVIfNpt+6jLPczJZFiRw==
version "12.19.15"
resolved "https://registry.yarnpkg.com/@types/node/-/node-12.19.15.tgz#0de7e978fb43db62da369db18ea088a63673c182"
integrity sha512-lowukE3GUI+VSYSu6VcBXl14d61Rp5hA1D+61r16qnwC0lYNSqdxcvRh0pswejorHfS+HgwBasM8jLXz0/aOsw==

"@types/normalize-package-data@^2.4.0":
version "2.4.0"
Expand Down Expand Up @@ -1949,9 +1949,9 @@
"@types/react" "^16"

"@types/react-native@*":
version "0.63.45"
resolved "https://registry.yarnpkg.com/@types/react-native/-/react-native-0.63.45.tgz#944a471d1e40e22eb8eae4369db7facf697c545e"
integrity sha512-HvsHe8hbcAuZJKcqUEN+E/qV1TNjL6venNUiQvDi7d1IlEK6ZyTrpIS937PwiNWc3UePNzR0xZ++aqpMAJqz1A==
version "0.63.46"
resolved "https://registry.yarnpkg.com/@types/react-native/-/react-native-0.63.46.tgz#942df5af29046c6f22227495e00d5297cc1cea73"
integrity sha512-SnBnWRErpISIaWk4K8kAfIKqSPdZ8fdH6HIw7kVdz6jMl/5FAf6iXeIwRfVZg1bCMh+ymNPCpSENNNEVprxj/w==
dependencies:
"@types/react" "*"

Expand Down Expand Up @@ -2003,12 +2003,12 @@
"@types/react-native" "*"
csstype "^2.2.0"

"@types/styled-system@5.1.2":
version "5.1.2"
resolved "https://registry.yarnpkg.com/@types/styled-system/-/styled-system-5.1.2.tgz#d75c40bc4a3bb0d0022eb3dcae58854129e9dd32"
integrity sha512-Byh33qthYnI6+qS0TRr4vqd+N/ax6ic1NFE6ZA16xuVr/EvYvSB8+diEP1lTSE7sP/MTdQpl+KaONREnyalDUA==
"@types/styled-system@5.1.10":
version "5.1.10"
resolved "https://registry.yarnpkg.com/@types/styled-system/-/styled-system-5.1.10.tgz#dcf5690dd837ca49b8de1f23cb99d510c7f4ecb3"
integrity sha512-OmVjC9OzyUckAgdavJBc+t5oCJrNXTlzWl9vo2x47leqpX1REq2qJC49SEtzbu1OnWSzcD68Uq3Aj8TeX+Kvtg==
dependencies:
csstype "^2.6.4"
csstype "^3.0.2"

"@types/styled-system__css@5.0.14":
version "5.0.14"
Expand Down Expand Up @@ -3344,9 +3344,9 @@ camelize@^1.0.0:
integrity sha1-FkpUg+Yw+kMh5a8HAg5TGDGyYJs=

caniuse-lite@^1.0.30001109, caniuse-lite@^1.0.30001173:
version "1.0.30001178"
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001178.tgz#3ad813b2b2c7d585b0be0a2440e1e233c6eabdbc"
integrity sha512-VtdZLC0vsXykKni8Uztx45xynytOi71Ufx9T8kHptSw9AL4dpqailUJJHavttuzUe1KYuBYtChiWv+BAb7mPmQ==
version "1.0.30001179"
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001179.tgz#b0803883b4471a6c62066fb1752756f8afc699c8"
integrity sha512-blMmO0QQujuUWZKyVrD1msR4WNDAqb/UPO1Sw2WWsQ7deoM5bJiicKnWJ1Y0NS/aGINSnKPIWBMw5luX+NDUCA==

capture-exit@^2.0.0:
version "2.0.0"
Expand Down Expand Up @@ -3557,9 +3557,9 @@ co@^4.6.0:
integrity sha1-bqa989hTrlTMuOR7+gvz+QMfsYQ=

codemirror@^5.51.0:
version "5.59.1"
resolved "https://registry.yarnpkg.com/codemirror/-/codemirror-5.59.1.tgz#cd6465555a87f8a2243eb41ffb460c777e15212c"
integrity sha512-d0SSW/PCCD4LoSCBPdnP0BzmZB1v3emomCUtVlIWgZHJ06yVeBOvBtOH7vYz707pfAvEeWbO9aP6akh8vl1V3w==
version "5.59.2"
resolved "https://registry.yarnpkg.com/codemirror/-/codemirror-5.59.2.tgz#ee674d3a4a8d241af38d52afc482625ba7393922"
integrity sha512-/D5PcsKyzthtSy2NNKCyJi3b+htRkoKv3idswR/tR6UAvMNKA7SrmyZy6fOONJxSRs1JlUWEDAbxqfdArbK8iA==

collect-v8-coverage@^1.0.0:
version "1.0.1"
Expand Down Expand Up @@ -4025,7 +4025,7 @@ cssstyle@^2.0.0:
dependencies:
cssom "~0.3.6"

csstype@^2.2.0, csstype@^2.6.4:
csstype@^2.2.0:
version "2.6.14"
resolved "https://registry.yarnpkg.com/csstype/-/csstype-2.6.14.tgz#004822a4050345b55ad4dcc00be1d9cf2f4296de"
integrity sha512-2mSc+VEpGPblzAxyeR+vZhJKgYg0Og0nnRi7pmRXFYYxSfnOnW8A5wwQb4n4cE2nIOzqKOAzLCaEX6aBmNEv8A==
Expand Down Expand Up @@ -4463,9 +4463,9 @@ ee-first@1.1.1:
integrity sha1-WQxhFWsK4vTwJVcyoViyZrxWsh0=

electron-to-chromium@^1.3.634:
version "1.3.642"
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.3.642.tgz#8b884f50296c2ae2a9997f024d0e3e57facc2b94"
integrity sha512-cev+jOrz/Zm1i+Yh334Hed6lQVOkkemk2wRozfMF4MtTR7pxf3r3L5Rbd7uX1zMcEqVJ7alJBnJL7+JffkC6FQ==
version "1.3.643"
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.3.643.tgz#fc196e17d01f4d874ef2307b009c0cd993ebe1c7"
integrity sha512-TGomM4gj8adt/uqRgPbu9F0yhUVAR1deww5X0fvbQgpGr9suSMjLgc4IwQ9YKGkp1t03cDbZum20OfAkiTYjAg==

elliptic@^6.5.3:
version "6.5.3"
Expand Down Expand Up @@ -5372,9 +5372,9 @@ flatted@^2.0.0:
integrity sha512-r5wGx7YeOwNWNlCA0wQ86zKyDLMQr+/RB8xy74M4hTphfmjlijTSSXGuH8rnvKZnfT9i+75zmd8jcKdMR4O6jA==

flow-parser@0.*:
version "0.142.0"
resolved "https://registry.yarnpkg.com/flow-parser/-/flow-parser-0.142.0.tgz#68792438f2593a9e3d862a5ce2278493991619aa"
integrity sha512-gkdbagtuYQw7fo/D1AwCsDpMyxp/bdZkgfq95ev2MoETD1OW84PhU+vitupwte+6AJc2MRJyCdgfWhan8AGhzA==
version "0.143.1"
resolved "https://registry.yarnpkg.com/flow-parser/-/flow-parser-0.143.1.tgz#c18e1745df97d1132e60036e88cbf1925b5094e4"
integrity sha512-DWmnt0P1tieuQErYeWmxCNIkzm5Fqd5sMH685v/jCtu8CAvdLEwKi45jqYhij178k+NAy+FNe2jDvQNs7WLBIA==

flush-write-stream@^1.0.0:
version "1.1.1"
Expand Down