Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: remove twin macro #46

Draft
wants to merge 12 commits into
base: main
Choose a base branch
from
Draft
8 changes: 8 additions & 0 deletions .storybook/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ module.exports = {
"@storybook/addon-interactions",
"storybook-addon-designs",
"storybook-dark-mode",
{
name: "@storybook/addon-postcss",
options: {
postcssLoaderOptions: {
implementation: require("postcss"),
},
},
},
],
framework: "@storybook/react",
};
48 changes: 1 addition & 47 deletions .storybook/preview.js
Original file line number Diff line number Diff line change
@@ -1,47 +1 @@
import React, { Children, useContext } from "react";
import { Theme, ThemeProvider } from "../src";
import { GlobalStyles } from "../src/GlobalStyles";
import { useDarkMode } from "storybook-dark-mode";
import tw, { css } from "twin.macro";

export const parameters = {
actions: { argTypesRegex: "^on[A-Z].*" },
controls: {
matchers: {
color: /(background|color)$/i,
date: /Date$/,
},
},
};

const backgroundColor = css`
html {
background-color: ${tw`bg-white`};

&.dark {
background-color: ${tw`bg-slate-800`};
}
}
`;

const StoryWrapper = ({ children }) => {
const dark = useDarkMode();
const { overrideMode } = useContext(Theme);
overrideMode(dark ? "dark" : "light");
return <>{children}</>;
};

export const decorators = [
(Story) => {
return (
<ThemeProvider>
<StoryWrapper>
<GlobalStyles />
<div css={backgroundColor}>
<Story />
</div>
</StoryWrapper>
</ThemeProvider>
);
},
];
import "../styles/globals.css";
11 changes: 7 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
"@swc/helpers": "^0.4.2",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-helmet": "^6.1.0"
"react-helmet": "^6.1.0",
"tailwind-styled-components": "^2.2.0",
"twin.macro": "^3.1.0"
},
"devDependencies": {
"@babel/core": "^7.18.5",
Expand All @@ -35,6 +37,7 @@
"@storybook/addon-essentials": "^6.5.9",
"@storybook/addon-interactions": "^6.5.9",
"@storybook/addon-links": "^6.5.9",
"@storybook/addon-postcss": "^2.0.0",
"@storybook/addons": "^6.5.9",
"@storybook/builder-webpack4": "^6.5.9",
"@storybook/manager-webpack4": "^6.5.9",
Expand All @@ -45,19 +48,19 @@
"@types/react": "^18.0.14",
"@types/react-dom": "^18.0.5",
"@types/react-helmet": "^6.1.5",
"autoprefixer": "^10.4.7",
"autoprefixer": "^10.4.13",
"babel-loader": "^8.2.5",
"babel-plugin-macros": "^3.1.0",
"babel-plugin-twin": "^1.0.2",
"chromatic": "^6.5.6",
"jest": "27",
"parcel": "^2.6.0",
"postcss": "^8.4.20",
"process": "^0.11.10",
"storybook": "^6.5.9",
"storybook-addon-designs": "^6.3.1",
"storybook-dark-mode": "^1.1.0",
"tailwindcss": "^3.1.3",
"twin.macro": "^2.8.2",
"tailwindcss": "^3.2.4",
"typescript": "^4.7.4"
},
"browserslist": "> 0.5%, last 2 versions, not dead",
Expand Down
6 changes: 6 additions & 0 deletions postcss.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
plugins: {
tailwindcss: {},
autoprefixer: {},
},
}
8 changes: 5 additions & 3 deletions src/GlobalStyles.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import React from "react";
import "../styles/globals.css";

import tw, { GlobalStyles as BaseStyles, css, styled, theme } from "twin.macro";

import { Global } from "@emotion/react";
import { Helmet } from "react-helmet";
import tw, { css, styled, theme, GlobalStyles as BaseStyles } from "twin.macro";
import { useMode } from "./hooks/useMode";

const customStyles = css`
Expand All @@ -10,6 +12,7 @@ const customStyles = css`
${tw`antialiased`}
}
`;
// todo - fix single prop types (primary !== boolean), see error message in console

type HtmlProps = { dark: boolean };
const HTML = styled.html<HtmlProps>(({ dark }) => [tw`h-full`, dark && "dark"]);
Expand Down Expand Up @@ -37,7 +40,6 @@ export const GlobalStyles = () => {
/>
<BODY dark={mode(false, true)} />
</Helmet>
<BaseStyles />
<Global styles={customStyles} />
</>
);
Expand Down
4 changes: 1 addition & 3 deletions src/components/Branding/Logo.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import "twin.macro";

import { ComponentMeta } from "@storybook/react";
import { Logo } from "./Logo";
import React from "react";
Expand All @@ -21,7 +19,7 @@ export default {

// More on component templates: https://storybook.js.org/docs/react/writing-stories/introduction#using-args
const Template = (args) => (
<div tw="w-96">
<div className="w-96">
<Logo {...args} />
</div>
);
Expand Down
6 changes: 3 additions & 3 deletions src/components/Marketing/Guide.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from "react";
import { ComponentMeta } from "@storybook/react";
import { Guide, GuideProps } from "./Guide";
import { AcademicCapIcon } from "@heroicons/react/solid";
import { ComponentMeta } from "@storybook/react";
import { Guide } from "./Guide";
import React from "react";

// More on default export: https://storybook.js.org/docs/react/writing-stories/introduction#default-export
export default {
Expand Down
109 changes: 82 additions & 27 deletions src/components/Marketing/Guide.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { FunctionComponent, ReactNode } from "react";
import { useMode } from "../../hooks/useMode";
import tw, { styled } from "twin.macro";

import tw from "tailwind-styled-components";

type BullitType = "numbers" | "checks" | ReactNode;

Expand All @@ -19,53 +19,108 @@ const Bullit: FunctionComponent<BullitProps> = ({ type, num }) => {
switch (type) {
case "numbers":
return (
<span tw="flex rounded-full bg-pink-600 text-white p-4 w-6 h-6 mr-2 items-center">
<span tw="block -ml-1">{num}</span>
</span>
<BullitWrapper>
<NumWrapper>{num}</NumWrapper>
</BullitWrapper>
);

case "checks":
return <span tw="mr-2 text-2xl font-black">✔</span>;
return <ChecksWrapper>✔</ChecksWrapper>;

default:
return <span tw="mr-2">{type}</span>;
return <DefaultWrapper>{type}</DefaultWrapper>;
}
};

const Section = styled.section(() => {
const mode = useMode();
return [
tw`p-0 m-0 text-slate-900 dark:text-slate-200`,
mode(tw`text-slate-900`, tw`text-slate-200`),
];
});

export const Guide: FunctionComponent<GuideProps> = ({
title,
items,
bullit,
}) => {
return (
<Section>
<div tw="container">
<h1 tw="text-3xl font-extrabold font-serif capitalize sm:text-4xl lg:text-5xl lg:text-center">
{title}
</h1>
<article tw="w-full lg:mx-16 lg:max-w-lg">
<ul tw="flex my-8 space-y-2 flex-col">
<SectionWrapper>
<div className="container">
<GuideHeader>{title}</GuideHeader>
<GuideArticle>
<GuideUl>
{items.map((item, i) => (
<li tw="flex items-center font-black font-sans text-lg" key={i}>
<GuideLi key={i}>
<Bullit type={bullit} num={i + 1} />
{item}
</li>
</GuideLi>
))}
</ul>
</article>
</GuideUl>
</GuideArticle>
</div>
</Section>
</SectionWrapper>
);
};

Guide.defaultProps = {
bullit: "numbers",
};

const SectionWrapper = tw.section`
p-0
m-0
text-slate-900
dark:text-slate-200
`;

const BullitWrapper = tw.span`
flex
rounded-full
bg-pink-600
text-white
p-4
w-6
h-6
mr-2
items-center
`;

const NumWrapper = tw.span`
block
-ml-1
`;

const ChecksWrapper = tw.span`
mr-2
text-2xl
font-black
`;

const DefaultWrapper = tw.span`
mr-2
`;

const GuideHeader = tw.h1`
text-3xl
font-extrabold
font-serif
capitalize
sm:text-4xl
lg:text-5xl
lg:text-center
`;

const GuideArticle = tw.article`
w-full
lg:mx-16
lg:max-w-lg
`;

const GuideUl = tw.ul`
flex
my-8
space-y-2
flex-col
`;

const GuideLi = tw.li`
flex
items-center
font-black
font-sans
text-lg
`;
Loading