|
| 1 | +import React, { ReactNode } from 'react'; |
| 2 | + |
| 3 | +type TextType = "display" | "headline" | "short-desc" | "paragraph" |
| 4 | +type TextFontWeight = "font-thin" | "font-extralight" | "font-light" | "font-normal" | "font-medium" | "font-semibold" | "font-bold" | "font-extrabold" | "font-black" |
| 5 | +type TextStyle = Record<TextType, { |
| 6 | + defaults: { |
| 7 | + fontWeight: TextFontWeight, |
| 8 | + size: number, |
| 9 | + color: string |
| 10 | + }, |
| 11 | + styles: { fontSize: string, lineHeight: string, letterSpacing: string }[] |
| 12 | +}> |
| 13 | +const styleMap: TextStyle = { |
| 14 | + "display": { |
| 15 | + defaults: { |
| 16 | + fontWeight: "font-bold", |
| 17 | + color: "text-[#3D4A5C]", |
| 18 | + size: 1 |
| 19 | + }, |
| 20 | + styles: [ |
| 21 | + { fontSize: "text-[11.6rem]", lineHeight: "leading-[13.2rem]", letterSpacing: "tracking-[3.5px]" }, |
| 22 | + { fontSize: "text-[9rem]", lineHeight: "leading-[10.62rem]", letterSpacing: "tracking-[3.5px]" }, |
| 23 | + { fontSize: "text-[7.5rem]", lineHeight: "leading-[8.37rem]", letterSpacing: "tracking-[3.5px]" }, |
| 24 | + { fontSize: "text-[6rem]", lineHeight: "leading-[6.87rem]", letterSpacing: "tracking-[2.5px]" }, |
| 25 | + ] |
| 26 | + }, |
| 27 | + "headline": { |
| 28 | + defaults: { |
| 29 | + fontWeight: "font-bold", |
| 30 | + color: "text-[#3D4A5C]", |
| 31 | + size: 1 |
| 32 | + }, |
| 33 | + styles: [ |
| 34 | + { fontSize: "text-[4.5rem]", lineHeight: "leading-[5.62rem]", letterSpacing: "tracking-[2.3px]" }, |
| 35 | + { fontSize: "text-[4rem]", lineHeight: "leading-[5rem]", letterSpacing: "tracking-[2.3px]" }, |
| 36 | + { fontSize: "text-[3rem]", lineHeight: "leading-[3.75rem]", letterSpacing: "tracking-[2.3px]" }, |
| 37 | + { fontSize: "text-[2.25rem]", lineHeight: "leading-[3.12rem]", letterSpacing: "tracking-[1px]" }, |
| 38 | + { fontSize: "text-[2rem]", lineHeight: "leading-[2.75rem]", letterSpacing: "tracking-[0.5px]" }, |
| 39 | + { fontSize: "text-[1.5rem]", lineHeight: "leading-[2.25rem]", letterSpacing: "tracking-[0.4px]" }, |
| 40 | + ] |
| 41 | + }, |
| 42 | + "short-desc": { |
| 43 | + defaults: { |
| 44 | + fontWeight: "font-medium", |
| 45 | + color: "text-black", |
| 46 | + size: 1 |
| 47 | + }, |
| 48 | + styles: [ |
| 49 | + { fontSize: "text-[1.875rem]", lineHeight: "leading-[2.687rem]", letterSpacing: "tracking-[0.5px]" }, |
| 50 | + { fontSize: "text-[1.75rem]", lineHeight: "leading-[2.687rem]", letterSpacing: "tracking-[0.5px]" }, |
| 51 | + { fontSize: "text-[1.625rem]", lineHeight: "leading-[2.5rem]", letterSpacing: "tracking-[0.5px]" }, |
| 52 | + { fontSize: "text-[1.5rem]", lineHeight: "leading-[2.25rem]", letterSpacing: "tracking-[0.5px]" }, |
| 53 | + ] |
| 54 | + }, |
| 55 | + "paragraph": { |
| 56 | + defaults: { |
| 57 | + fontWeight: "font-normal", |
| 58 | + color: "text-black", |
| 59 | + size: 1 |
| 60 | + }, |
| 61 | + styles: [ |
| 62 | + { fontSize: "text-[1.375rem]", lineHeight: "leading-[2.187rem]", letterSpacing: "tracking-[0.3px]" }, |
| 63 | + { fontSize: "text-[1.25rem]", lineHeight: "leading-[2rem]", letterSpacing: "tracking-[0.3px]" }, |
| 64 | + { fontSize: "text-[1.125rem]", lineHeight: "leading-[1.87rem]", letterSpacing: "tracking-[0.3px]" }, |
| 65 | + { fontSize: "text-[1rem]", lineHeight: "leading-[1.75rem]", letterSpacing: "tracking-[0.3px]" }, |
| 66 | + { fontSize: "text-[0.87rem]", lineHeight: "leading-[1.5rem]", letterSpacing: "tracking-[0.2px]" }, |
| 67 | + { fontSize: "text-[0.75rem]", lineHeight: "leading-[1.25rem]", letterSpacing: "tracking-[0.2px]" }, |
| 68 | + ] |
| 69 | + }, |
| 70 | +} |
| 71 | + |
| 72 | +export interface TextProps { |
| 73 | + type?: TextType |
| 74 | + size?: number |
| 75 | + italic?: boolean |
| 76 | + color?: string |
| 77 | + weight?: TextFontWeight |
| 78 | + children?: ReactNode |
| 79 | +} |
| 80 | + |
| 81 | +const Text: React.FC<TextProps> = ({ |
| 82 | + type = "paragraph", |
| 83 | + size = styleMap[type].defaults.size, |
| 84 | + weight = styleMap[type].defaults.fontWeight, |
| 85 | + color = styleMap[type].defaults.color, |
| 86 | + italic = false, |
| 87 | + children |
| 88 | +}: TextProps) => { |
| 89 | + const styles = Object.values(styleMap[type].styles[size-1]).join(' ') |
| 90 | + const additionalClasses = [ |
| 91 | + `bootwind-text bootwind-text-${type}`, |
| 92 | + italic ? 'italic' : '',, |
| 93 | + weight, |
| 94 | + color |
| 95 | + ].join(' ') |
| 96 | + |
| 97 | + const classes = `${additionalClasses} ${styles}` |
| 98 | + |
| 99 | + return ( |
| 100 | + <p className={classes}>{children}</p> |
| 101 | + ) |
| 102 | +}; |
| 103 | + |
| 104 | +export default Text; |
0 commit comments