-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: preserve styled components composability
- Loading branch information
1 parent
dd8c34f
commit 0141663
Showing
2 changed files
with
64 additions
and
101 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
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 |
---|---|---|
@@ -1,101 +1,76 @@ | ||
import { variant } from "styled-system"; | ||
import styled from "styled-components"; | ||
import { DefaultNDSThemeType } from "../theme.type"; | ||
import { addStyledProps } from "../StyledProps"; | ||
import { withComponentVariant } from "../NDSProvider/ComponentVariantContext"; | ||
import { useComponentVariant } from "../NDSProvider/ComponentVariantContext"; | ||
import Text, { TextProps } from "./Text"; | ||
|
||
export const Heading1 = withComponentVariant( | ||
styled(Text).attrs(() => ({ | ||
as: "h1", | ||
}))<TextProps>( | ||
({ theme }) => ({ | ||
fontSize: theme.fontSizes.heading1, | ||
lineHeight: theme.lineHeights.heading1, | ||
fontWeight: theme.fontWeights.light, | ||
marginTop: 0, | ||
marginBottom: theme.space.x6, | ||
}), | ||
({ theme }) => | ||
variant({ | ||
variants: { | ||
touch: { | ||
fontWeight: theme.fontWeights.bold, | ||
marginBottom: theme.space.none, | ||
}, | ||
}, | ||
}), | ||
addStyledProps | ||
) | ||
const useVariantStyles = ({ theme }: { theme: DefaultNDSThemeType }) => { | ||
const componentVariant = useComponentVariant(); | ||
|
||
return variant({ | ||
variants: { | ||
touch: { | ||
fontWeight: theme.fontWeights.bold, | ||
marginBottom: theme.space.none, | ||
}, | ||
}, | ||
prop: "variant", | ||
})({ theme, variant: componentVariant }); | ||
}; | ||
|
||
export const Heading1 = styled(Text).attrs(() => ({ | ||
as: "h1", | ||
}))<TextProps>( | ||
({ theme }) => ({ | ||
fontSize: theme.fontSizes.heading1, | ||
lineHeight: theme.lineHeights.heading1, | ||
fontWeight: theme.fontWeights.light, | ||
marginTop: 0, | ||
marginBottom: theme.space.x6, | ||
}), | ||
useVariantStyles, | ||
addStyledProps | ||
); | ||
|
||
export const Heading2 = withComponentVariant( | ||
styled(Text).attrs(() => ({ | ||
as: "h2", | ||
}))( | ||
({ theme }) => ({ | ||
fontSize: theme.fontSizes.heading2, | ||
lineHeight: theme.lineHeights.heading2, | ||
fontWeight: theme.fontWeights.normal, | ||
marginTop: 0, | ||
marginBottom: theme.space.x2, | ||
}), | ||
({ theme }) => | ||
variant({ | ||
variants: { | ||
touch: { | ||
fontWeight: theme.fontWeights.bold, | ||
marginBottom: theme.space.none, | ||
}, | ||
}, | ||
}), | ||
addStyledProps | ||
) | ||
export const Heading2 = styled(Text).attrs(() => ({ | ||
as: "h2", | ||
}))( | ||
({ theme }) => ({ | ||
fontSize: theme.fontSizes.heading2, | ||
lineHeight: theme.lineHeights.heading2, | ||
fontWeight: theme.fontWeights.normal, | ||
marginTop: 0, | ||
marginBottom: theme.space.x2, | ||
}), | ||
useVariantStyles, | ||
addStyledProps | ||
); | ||
|
||
export const Heading3 = withComponentVariant( | ||
styled(Text).attrs(() => ({ | ||
as: "h3", | ||
}))( | ||
({ theme }) => ({ | ||
fontSize: theme.fontSizes.heading3, | ||
lineHeight: theme.lineHeights.heading3, | ||
fontWeight: theme.fontWeights.medium, | ||
marginTop: 0, | ||
marginBottom: theme.space.x1, | ||
}), | ||
({ theme }) => | ||
variant({ | ||
variants: { | ||
touch: { | ||
fontWeight: theme.fontWeights.bold, | ||
marginBottom: theme.space.none, | ||
}, | ||
}, | ||
}), | ||
addStyledProps | ||
) | ||
export const Heading3 = styled(Text).attrs(() => ({ | ||
as: "h3", | ||
}))( | ||
({ theme }) => ({ | ||
fontSize: theme.fontSizes.heading3, | ||
lineHeight: theme.lineHeights.heading3, | ||
fontWeight: theme.fontWeights.medium, | ||
marginTop: 0, | ||
marginBottom: theme.space.x1, | ||
}), | ||
useVariantStyles, | ||
addStyledProps | ||
); | ||
|
||
export const Heading4 = withComponentVariant( | ||
styled(Text).attrs(() => ({ | ||
as: "h4", | ||
}))( | ||
({ theme }) => ({ | ||
fontSize: theme.fontSizes.heading4, | ||
lineHeight: theme.lineHeights.heading4, | ||
fontWeight: theme.fontWeights.bold, | ||
marginTop: 0, | ||
marginBottom: theme.space.x1, | ||
}), | ||
({ theme }) => | ||
variant({ | ||
variants: { | ||
touch: { | ||
fontWeight: theme.fontWeights.bold, | ||
marginBottom: theme.space.none, | ||
}, | ||
}, | ||
}), | ||
addStyledProps | ||
) | ||
export const Heading4 = styled(Text).attrs(() => ({ | ||
as: "h4", | ||
}))( | ||
({ theme }) => ({ | ||
fontSize: theme.fontSizes.heading4, | ||
lineHeight: theme.lineHeights.heading4, | ||
fontWeight: theme.fontWeights.bold, | ||
marginTop: 0, | ||
marginBottom: theme.space.x1, | ||
}), | ||
useVariantStyles, | ||
addStyledProps | ||
); |