I have a formatting object named typography that includes various styles. One common issue I've encountered is that the line-height property is consistently set to 135%. Anticipating that this might change in the future, I am looking for a way to centralize this value rather than repeating it multiple times within the object. Below is a snippet of my current typography object:
const typography = {
globalStyles: `
font-family: Lato;
font-style: normal;
color: #000000;`,
header: {
XXL: `
font-weight: normal;
font-size: 37px;
line-height: 135%;`,
XL: `
font-weight: normal;
font-size: 33px;
line-height: 135%;`,
L: `
font-weight: normal;
font-size: 29px;
line-height: 135%;`,
M: `
font-weight: normal;
font-size: 25px;
line-height: 135%;`,
S: `
font-weight: normal;
font-size: 21px;
line-height: 135%;`,
bold: {
...
},
},
body: {
...
}
}
In an attempt to address this issue, I experimented with creating a lineHeight property lineHeight:line-height: 135%;
and using the spread operator ...this.lineHeight
to apply it. However, this approach did not yield the desired outcome. Please see the revised code snippet below:
const typography = {
lineHeight: `line-height: 135%;`,
globalStyles: `
font-family: Lato;
font-style: normal;
color: #000000;`,
header: {
XXL: `
font-weight: normal;
font-size: 37px;
...this.lineHeight`,
XL: `
font-weight: normal;
font-size: 33px;
...this.lineHeight`,
L: `
font-weight: normal;
font-size: 29px;
...this.lineHeight `,
M: `
font-weight: normal;
font-size: 25px;
...this.lineHeight`,
S: `
font-weight: normal;
font-size: 21px;
...this.lineHeight`,
bold: {
...
},
},
body: {
...
}
}
Any assistance on this matter would be greatly appreciated!