-
-
Notifications
You must be signed in to change notification settings - Fork 183
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Twin now has support for [SolidJS](https://www.solidjs.com/) When we define the solid preset like this: ```js // babel-plugin-macros.config.js module.exports = { twin: { preset: 'solid', }, } ``` Or in `package.json`: ```js // package.json "babelMacros": { "twin": { "preset": "solid" } }, ``` Twin will use the imports from [solid-styled-components](https://github.com/solidjs/solid-styled-components) - the official css-in-js library provided by the SolidJS team. Here are the conversions that happen during common styling patterns: ### `tw` prop ```js function Component() { return <div tw="block" /> } // ↓ ↓ ↓ ↓ ↓ ↓ import { styled } from "solid-styled-components"; const TwComponent = styled("div")({ "display": "block" }); function Component() { return <TwComponent data-tw="block" />; } ``` ### `css` prop ```js const Component = ({ children }) => ( <div css={[]}>{children}</div> ) // ↓ ↓ ↓ ↓ ↓ ↓ import { styled } from "solid-styled-components"; const TwComponent = styled("div")([]); const Component = ({ children }) => ( <TwComponent>{children}</TwComponent> ) ``` ### `tw.div` ```js import tw from "twin.macro" const Component = tw.div`block` // ↓ ↓ ↓ ↓ ↓ ↓ import { styled } from "solid-styled-components"; const Component = styled("div")({ "display": "block" }); ``` ### `styled.div` ```js import { styled } from "twin.macro" const Component = styled.div([]) // ↓ ↓ ↓ ↓ ↓ ↓ import { styled } from "solid-styled-components"; const Component = styled("div")([]); ``` ### More - [StackBlitz example](https://stackblitz.com/github/ben-rogerson/twin.examples/tree/master/vite-solid-typescript?file=src/App.tsx) - [SolidJS example](https://github.com/ben-rogerson/twin.examples/blob/master/vite-solid-typescript/README.md) - [solid-styled-components](https://github.com/solidjs/solid-styled-components) Related #398
- Loading branch information
1 parent
d8bd0c5
commit e438582
Showing
13 changed files
with
250 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,8 @@ const TWIN_CONFIG_DEFAULTS = { | |
autoCssProp: false, | ||
config: undefined, | ||
convertHtmlElementToStyled: false, | ||
convertStyledDot: false, | ||
convertStyledDotToParam: false, | ||
convertStyledDotToFunction: false, | ||
css: { import: '', from: '' }, | ||
dataCsProp: false, | ||
dataTwProp: false, | ||
|
@@ -21,26 +22,38 @@ const TWIN_CONFIG_DEFAULTS = { | |
sassyPseudo: false, | ||
stitchesConfig: undefined, | ||
styled: { import: '', from: '' }, | ||
} | ||
} as const | ||
|
||
// Defaults for different css-in-js libraries | ||
const configDefaultsGoober = { sassyPseudo: true } // Sets selectors like hover to &:hover | ||
const configDefaultsGoober = { | ||
sassyPseudo: true, // Sets selectors like hover to &:hover | ||
} as const | ||
|
||
const configDefaultsSolid = { | ||
sassyPseudo: true, // Sets selectors like hover to &:hover | ||
moveTwPropToStyled: true, // Move the tw prop to a styled definition | ||
convertHtmlElementToStyled: true, // Add a styled definition on css prop elements | ||
convertStyledDotToFunction: true, // Convert styled.[element] to a default syntax | ||
} as const | ||
|
||
const configDefaultsStitches = { | ||
sassyPseudo: true, // Sets selectors like hover to &:hover | ||
convertStyledDot: true, // Convert styled.[element] to a default syntax | ||
convertStyledDotToParam: true, // Convert styled.[element] to a default syntax | ||
moveTwPropToStyled: true, // Move the tw prop to a styled definition | ||
convertHtmlElementToStyled: true, // For packages like stitches, add a styled definition on css prop elements | ||
convertHtmlElementToStyled: true, // Add a styled definition on css prop elements | ||
stitchesConfig: undefined, // Set the path to the stitches config | ||
moveKeyframesToGlobalStyles: true, // Stitches doesn't support inline @keyframes | ||
} | ||
} as const | ||
|
||
function configDefaultsTwin({ | ||
isSolid, | ||
isGoober, | ||
isStitches, | ||
isDev, | ||
}: GetPackageUsed & { isDev: boolean }): TwinConfigAll { | ||
return { | ||
...TWIN_CONFIG_DEFAULTS, | ||
...(isSolid && configDefaultsSolid), | ||
...(isGoober && configDefaultsGoober), | ||
...(isStitches && configDefaultsStitches), | ||
dataTwProp: isDev, | ||
|
@@ -52,7 +65,13 @@ function isBoolean(value: unknown): boolean { | |
return typeof value === 'boolean' | ||
} | ||
|
||
const allowedPresets = ['styled-components', 'emotion', 'goober', 'stitches'] | ||
const allowedPresets = [ | ||
'styled-components', | ||
'emotion', | ||
'goober', | ||
'stitches', | ||
'solid', | ||
] | ||
|
||
type ConfigTwinValidators = Record< | ||
keyof typeof TWIN_CONFIG_DEFAULTS & 'disableColorVariables', | ||
|
@@ -76,6 +95,10 @@ const configTwinValidators: ConfigTwinValidators = { | |
(value: unknown): boolean => !value, | ||
'The “autoCssProp” feature has been removed from [email protected]+\nThis means the css prop must be added by styled-components instead.\nSetup info at https://twinredirect.page.link/auto-css-prop\n\nRemove the “autoCssProp” item from your config to avoid this message.', | ||
], | ||
convertStyledDot: [ | ||
(value: unknown): boolean => !value, | ||
'The “convertStyledDot” feature was changed to “convertStyledDotParam”.', | ||
], | ||
disableColorVariables: [ | ||
(value: unknown): boolean => !value, | ||
'The disableColorVariables feature has been removed from twin.macro@3+\n\nRemove the disableColorVariables item from your config to avoid this message.', | ||
|
@@ -97,9 +120,13 @@ const configTwinValidators: ConfigTwinValidators = { | |
isBoolean, | ||
'The config “disableCsProp” can only be a boolean', | ||
], | ||
convertStyledDot: [ | ||
convertStyledDotToParam: [ | ||
isBoolean, | ||
'The config “convertStyledDotToParam” can only be a boolean', | ||
], | ||
convertStyledDotToFunction: [ | ||
isBoolean, | ||
'The config “convertStyledDot” can only be a boolean', | ||
'The config “convertStyledDotToFunction” can only be a boolean', | ||
], | ||
moveTwPropToStyled: [ | ||
isBoolean, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.