Skip to content

Commit

Permalink
SUM-253 | customTwMerge (#67)
Browse files Browse the repository at this point in the history
  • Loading branch information
rebeccahongsf authored Sep 18, 2024
1 parent 81ae830 commit 4411fb8
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 28 deletions.
2 changes: 1 addition & 1 deletion src/components/elements/headers.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import twMerge from "@lib/utils/twMergeConfig"
import {HtmlHTMLAttributes} from "react"
import {twMerge} from "tailwind-merge"

type Props = HtmlHTMLAttributes<HTMLHeadingElement>

Expand Down
18 changes: 18 additions & 0 deletions src/lib/utils/twMergeConfig.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import {extendTailwindMerge} from "tailwind-merge"

// Creates an array containing type-# classes from 0 to 1
const typeClasses = Array.from({length: 10}, (_, i) => `type-${i}`)
// Creates an array containing text-# classes from 11 to 30
const textClasses = Array.from({length: 20}, (_, i) => `text-${i + 11}`)

const typographyClasses = [...textClasses, ...typeClasses]

const twMerge = extendTailwindMerge({
extend: {
classGroups: {
"font-size": typographyClasses,
},
},
})

export default twMerge
51 changes: 25 additions & 26 deletions tailwind.config.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,26 @@
/** @type {import('tailwindcss').Config} */

const decanter = require('decanter');
const decanter = require("decanter")

const path = require('path');
const dir = path.resolve(__dirname, 'src/styles');
const path = require("path")
const dir = path.resolve(__dirname, "src/styles")

let twoColumn = {}, threeColumn = {}, i;
let twoColumn = {},
threeColumn = {},
i
for (i = 1; i <= 4; i++) {
twoColumn[`1-${i}`] = `minmax(0, 1fr) minmax(0, ${i}fr)`;
twoColumn[`${i}-1`] = `minmax(0, ${i}fr) minmax(0, 1fr)`;
twoColumn[`1-${i}`] = `minmax(0, 1fr) minmax(0, ${i}fr)`
twoColumn[`${i}-1`] = `minmax(0, ${i}fr) minmax(0, 1fr)`
}

for (i = 1; i <= 4; i++) {
threeColumn[`${i}-1-1`] = `minmax(0, ${i}fr) minmax(0, 1fr) minmax(0, 1fr)`;
threeColumn[`1-${i}-1`] = `minmax(0, 1fr) minmax(0, ${i}fr) minmax(0, 1fr)`;
threeColumn[`1-1-${i}`] = `minmax(0, 1fr) minmax(0, 1fr) minmax(0, ${i}fr)`;
threeColumn[`${i}-1-1`] = `minmax(0, ${i}fr) minmax(0, 1fr) minmax(0, 1fr)`
threeColumn[`1-${i}-1`] = `minmax(0, 1fr) minmax(0, ${i}fr) minmax(0, 1fr)`
threeColumn[`1-1-${i}`] = `minmax(0, 1fr) minmax(0, 1fr) minmax(0, ${i}fr)`
}

module.exports = {
content: [
'./src/**/*.{js,ts,jsx,tsx,mdx}',
'./app/**/*.{js,ts,jsx,tsx,mdx}',
],
content: ["./src/**/*.{js,ts,jsx,tsx,mdx}", "./app/**/*.{js,ts,jsx,tsx,mdx}"],
theme: {
fontFamily: decanter.theme.fontFamily,
decanter: decanter.theme.decanter,
Expand All @@ -33,32 +32,32 @@ module.exports = {
},
gridTemplateColumns: {...twoColumn, ...threeColumn},
containers: {
'8xl': '80rem',
'9xl': '90rem',
'10xl': '100rem',
'11xl': '110rem',
'12xl': '120rem',
'13xl': '130rem',
'14xl': '140rem',
'15xl': '150rem',
"8xl": "80rem",
"9xl": "90rem",
"10xl": "100rem",
"11xl": "110rem",
"12xl": "120rem",
"13xl": "130rem",
"14xl": "140rem",
"15xl": "150rem",
},
screens: {
'4xl': '2000px',
"4xl": "2000px",
},
scale: {
'-100': '-1'
"-100": "-1",
},
fontFamily: {
roboto: ['var(--font-roboto)', 'sans-serif'],
roboto: ["var(--font-roboto)", "sans-serif"],
},
},
},
plugins: [
...decanter.plugins,
require('@tailwindcss/container-queries'),
require("@tailwindcss/container-queries"),
require(`${dir}/typography/local-footer.tsx`)(),
require(`${dir}/typography/global-message.tsx`)(),
require(`${dir}/typography/wysiwyg.tsx`)(),
require(`${dir}/centered-container.tsx`)(),
],
};
}
8 changes: 7 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@
"@lib/*": ["./src/lib/*"]
}
},
"include": ["next-env.d.ts", "src/**/*.tsx", "app/**/*.tsx", ".storybook/stories/**/*.tsx", ".next/types/**/*.ts"],
"include": [
"next-env.d.ts",
"src/**/*.tsx",
"app/**/*.tsx",
".storybook/stories/**/*.tsx",
".next/types/**/*.ts",
],
"exclude": ["node_modules"]
}

0 comments on commit 4411fb8

Please sign in to comment.