Skip to content

Commit

Permalink
♻️ Updates on naming
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Marszalek committed Oct 23, 2020
1 parent eb61c1a commit f7e1bff
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 47 deletions.
2 changes: 1 addition & 1 deletion libraries/core-react/src/Banner/BannerMessage.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { FC } from 'react'
import styled from 'styled-components'
import { Typography } from '../Typography'
import { Props as TypographyProps } from '../Typography/Typography'
import { TypographyProps } from '../Typography/Typography'

const StyledBannerMessage = styled(Typography)``

Expand Down
96 changes: 50 additions & 46 deletions libraries/core-react/src/Typography/Typography.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ const findTypography = (
return (typography[group] as unknown)[variantName] as TypographyType
}

const findColor = (inputColor: ColorVariants): string =>
const findColor: (a: ColorVariants | string) => string = (
inputColor = null,
): string =>
typeof colors[inputColor] === 'undefined' ? inputColor : colors[inputColor]

const toVariantName = (
Expand Down Expand Up @@ -82,64 +84,66 @@ const StyledTypography = styled.p<StyledProps>`
`}
`

export type Props = {
export type TypographyProps = {
variant?: TypographyVariants
group?: TypographyGroups
bold?: boolean
italic?: boolean
link?: boolean
color?: ColorVariants
color?: ColorVariants | string
token?: Partial<TypographyType>
lines?: number
as?: ElementType
} & React.HTMLAttributes<HTMLElement>

export const Typography = forwardRef<HTMLElement, Props>(function EdsTypography(
{
variant = 'body_short',
children,
bold,
italic,
link,
group,
token,
as: providedAs,
...other
},
ref,
) {
const as: ElementType = providedAs
? providedAs
: getElementType(variant, link)
export const Typography = forwardRef<HTMLElement, TypographyProps>(
function Typography(
{
variant = 'body_short',
children,
bold,
italic,
link,
group,
token,
as: providedAs,
...other
},
ref,
) {
const as: ElementType = providedAs
? providedAs
: getElementType(variant, link)

const variantName = toVariantName(
variant,
bold,
italic,
link,
) as TypographyVariants
const variantName = toVariantName(
variant,
bold,
italic,
link,
) as TypographyVariants

const typography = findTypography(variantName, group)
const typography = findTypography(variantName, group)

if (typeof typography === 'undefined') {
throw new Error(
`Typography variant not found for variant "${variantName}" ("${variant}") & group "${
group || ''
}"`,
)
}
if (typeof typography === 'undefined') {
throw new Error(
`Typography variant not found for variant "${variantName}" ("${variant}") & group "${
group || ''
}"`,
)
}

return (
<StyledTypography
as={as}
typography={{ ...typography, ...token }}
link={link}
ref={ref}
{...other}
>
{children}
</StyledTypography>
)
})
return (
<StyledTypography
as={as}
typography={{ ...typography, ...token }}
link={link}
ref={ref}
{...other}
>
{children}
</StyledTypography>
)
},
)

// Typography.displayName = 'EdsTypography'

0 comments on commit f7e1bff

Please sign in to comment.