From 289f73f52625f74c0a19e37216dafecd43f8b8e2 Mon Sep 17 00:00:00 2001 From: Jamie Henson Date: Mon, 18 Nov 2024 22:17:53 +0000 Subject: [PATCH] feat: use Tailwind theming prefixes over custom approach --- scripts/compute-colors.ts | 81 - .../ContactFooter.stories.tsx.snap | 6 +- .../__snapshots__/Expander.stories.tsx.snap | 2 +- src/core/FeaturedLink.tsx | 4 +- .../FeaturedLink.stories.tsx.snap | 10 +- .../__snapshots__/Footer.stories.tsx.snap | 12 +- src/core/Icon.tsx | 101 +- src/core/Icon/EncapsulatedIcon.tsx | 12 +- src/core/Icon/Icon.stories.tsx | 66 +- .../Icon/__snapshots__/Icon.stories.tsx.snap | 1633 +++++++---------- src/core/Pricing/PricingCards.stories.tsx | 11 +- src/core/Pricing/PricingCards.tsx | 95 +- src/core/Pricing/data.tsx | 42 +- src/core/Pricing/types.ts | 6 +- src/core/ProductTile.tsx | 61 +- src/core/ProductTile/ProductTile.stories.tsx | 2 +- .../ProductTile.stories.tsx.snap | 206 +-- .../__snapshots__/Slider.stories.tsx.snap | 42 +- .../__snapshots__/Table.stories.tsx.snap | 30 +- src/core/Tooltip.tsx | 16 +- .../__snapshots__/Tooltip.stories.tsx.snap | 24 +- src/core/hooks/useTheming.tsx | 25 - .../__snapshots__/Button.stories.tsx.snap | 18 +- .../__snapshots__/Forms.stories.tsx.snap | 4 +- src/core/styles/colors/Colors.stories.tsx | 43 +- .../__snapshots__/Colors.stories.tsx.snap | 543 +++--- src/core/styles/colors/types.ts | 10 +- tailwind.config.js | 1 + 28 files changed, 1360 insertions(+), 1746 deletions(-) delete mode 100644 scripts/compute-colors.ts delete mode 100644 src/core/hooks/useTheming.tsx diff --git a/scripts/compute-colors.ts b/scripts/compute-colors.ts deleted file mode 100644 index 95e8a2511..000000000 --- a/scripts/compute-colors.ts +++ /dev/null @@ -1,81 +0,0 @@ -import fs from "fs"; -import path from "path"; -import { invertTailwindClassVariant } from "../src/core/styles/colors/utils"; -import { colors, prefixes, variants } from "../src/core/styles/colors/types"; - -const directoryPath = path.join(__dirname, "../src"); -const outputPath = path.join( - __dirname, - "../src/core/styles/colors", - "computed-colors.json", -); - -const joinedVariants = variants.join("|"); -const joinedPrefixes = prefixes.join("|"); -const joinedColors = colors.join("|"); -const pattern = `themeColor\\("((?:${joinedVariants}-)(${joinedPrefixes})-(${joinedColors})-(000|[1-9]00|1[0-3]00))"\\)`; -const regex = new RegExp(pattern, "g"); - -const findStringInFiles = (dir: string) => { - const results: string[] = []; - - const readDirectory = (dir: string) => { - let files: string[]; - try { - files = fs.readdirSync(dir); - } catch (error) { - console.error(`Error reading directory ${dir}:`, error); - return; - } - - files.forEach((file) => { - const filePath = path.join(dir, file); - let stat; - try { - stat = fs.statSync(filePath); - } catch (error) { - console.error(`Error accessing ${filePath}:`, error); - return; - } - - if (stat.isDirectory()) { - readDirectory(filePath); - } else if (filePath.endsWith(".tsx")) { - let content = ""; - try { - content = fs.readFileSync(filePath, "utf-8"); - const matches = [...content.matchAll(regex)].map((match) => match[1]); - - if (matches.length > 0) { - results.push(...matches); - } - } catch (error) { - console.error(`Error reading file ${filePath}:`, error); - return; - } - } - }); - }; - - readDirectory(dir); - return Array.from(new Set(results)).sort(); -}; - -const matches = findStringInFiles(directoryPath); - -const flippedMatches = matches.map((match) => - invertTailwindClassVariant(match), -); - -try { - const outputDir = path.dirname(outputPath); - if (!fs.existsSync(outputDir)) { - fs.mkdirSync(outputDir, { recursive: true }); - } - fs.writeFileSync(outputPath, JSON.stringify(flippedMatches)); - console.log( - `🎨 Tailwind theme classes have been computed and written to JSON files.`, - ); -} catch (error) { - console.error(`Error persisting computed colors:`, error); -} diff --git a/src/core/ContactFooter/__snapshots__/ContactFooter.stories.tsx.snap b/src/core/ContactFooter/__snapshots__/ContactFooter.stories.tsx.snap index 9678682c5..82458df10 100644 --- a/src/core/ContactFooter/__snapshots__/ContactFooter.stories.tsx.snap +++ b/src/core/ContactFooter/__snapshots__/ContactFooter.stories.tsx.snap @@ -6,7 +6,7 @@ exports[`JS Components/Contact Footer Default smoke-test 1`] = ` >