Home
Softono
b

ben-rogerson

Professional software vendor delivering innovative solutions on the Softono platform. Specialized in both open-source and proprietary software development.

Total Products
2

Software by ben-rogerson

twin.macro
Open Source

twin.macro

<p align="center"> <a href="https://github.com/ben-rogerson/twin.macro#gh-light-mode-only" target="_blank"> <img src="./.github/logo-light.svg" alt="Twin examples" width="199" height="70"> </a> <a href="https://github.com/ben-rogerson/twin.macro#gh-dark-mode-only" target="_blank"> <img src="./.github/logo-dark.svg" alt="Twin examples" width="199" height="70"> </a> </p> <p align="center"> The <em>magic</em> of Tailwind with the <em>flexibility</em> of css-in-js.<br><br> <a href="https://www.npmjs.com/package/twin.macro"><img src="https://img.shields.io/npm/dt/twin.macro.svg" alt="Total Downloads"></a> <a href="https://www.npmjs.com/package/twin.macro"><img src="https://img.shields.io/npm/v/twin.macro.svg" alt="Latest Release"></a> <a href="https://discord.gg/Xj6x9z7"><img src="https://img.shields.io/discord/705884695400939552?label=discord&logo=discord" alt="Discord"></a> <br> <br> <a href="https://stackblitz.com/github/ben-rogerson/twin.examples/tree/master/vite-styled-components-typescript?file=src/App.tsx"> <img alt="Open in StackBlitz" src="https://developer.stackblitz.com/img/open_in_stackblitz_small.svg" /> </a> </p> --- Style jsx elements using Tailwind classes: ```js import 'twin.macro' const Input = () => <input tw="border hover:border-black" /> ``` Nest Twin’s `tw` import within a css prop to add conditional styles: ```js import tw from 'twin.macro' const Input = ({ hasHover }) => ( <input css={[tw`border`, hasHover && tw`hover:border-black`]} /> ) ``` Or mix sass styles with the css import: ```js import tw, { css } from 'twin.macro' const hoverStyles = css` &:hover { border-color: black; ${tw`text-black`} } ` const Input = ({ hasHover }) => ( <input css={[tw`border`, hasHover && hoverStyles]} /> ) ``` ### Styled Components You can also use the tw import to create and style new components: ```js import tw from 'twin.macro' const Input = tw.input`border hover:border-black` ``` And clone and style existing components: ```js const PurpleInput = tw(Input)`border-purple-500` ``` Switch to the styled import to add conditional styling: ```js import tw, { styled } from 'twin.macro' const StyledInput = styled.input(({ hasBorder }) => [ `color: black;`, hasBorder && tw`border-purple-500`, ]) const Input = () => <StyledInput hasBorder /> ``` Or use backticks to mix with sass styles: ```js import tw, { styled } from 'twin.macro' const StyledInput = styled.input` color: black; ${({ hasBorder }) => hasBorder && tw`border-purple-500`} ` const Input = () => <StyledInput hasBorder /> ``` ## How it works When babel runs over your javascript or typescript files at compile time, twin grabs your classes and converts them into css objects. These css objects are then passed into your chosen css-in-js library without the need for an extra client-side bundle: ```js import tw from 'twin.macro' tw`text-sm md:text-lg` // ↓ ↓ ↓ ↓ ↓ ↓ { fontSize: '0.875rem', '@media (min-width: 768px)': { fontSize: '1.125rem', }, } ``` ## Features **👌 Simple imports** - Twin collapses imports from common styling libraries into a single import: ```diff - import styled from '@emotion/styled' - import css from '@emotion/react' + import { styled, css } from 'twin.macro' ``` **🐹 Adds no size to your build** - Twin converts the classes you’ve used into css objects using Babel and then compiles away, leaving no runtime code **🍱 Apply variants to multiple classes at once with variant groups** ```js import 'twin.macro' const interactionStyles = () => ( <div tw="hover:(text-black underline) focus:(text-blue-500 underline)" /> ) const mediaStyles = () => <div tw="sm:(w-4 mt-3) lg:(w-8 mt-6)" /> const pseudoElementStyles = () => <div tw="before:(block w-10 h-10 bg-black)" /> const stackedVariants = () => <div tw="sm:hover:(bg-black text-white)" /> const groupsInGroups = () => <div tw="sm:(bg-black hover:(bg-white w-10))" /> ``` **🛎 Helpful suggestions for mistypings** - Twin chimes in with class and variant values from your Tailwind config: ```bash ✕ ml-1.25 was not found Try one of these classes: - ml-1.5 > 0.375rem - ml-1 > 0.25rem - ml-10 > 2.5rem ``` **🖌️ Use the theme import to add values from your tailwind config** ```js import { css, theme } from 'twin.macro' const Input = () => <input css={css({ color: theme`colors.purple.500` })} /> ``` See more examples [using the theme import →](https://github.com/ben-rogerson/twin.macro/pull/106) **💡 Works with the official tailwind vscode plugin** - Avoid having to look up your classes with auto-completions straight from your Tailwind config - [setup instructions →](https://github.com/ben-rogerson/twin.macro/discussions/227) **💥 Add !important to any class with a trailing or leading bang!** ```js <div tw="hidden!" /> || <div tw="!hidden" /> // ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ <div css={{ "display": "none !important" }} /> ``` Add !important to multiple classes with bracket groups: ```js <div tw="(hidden ml-auto)!" /> // ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ <div css={{ "display": "none !important", "marginLeft": "auto !important" }} /> ``` ## Get started Twin works with many modern stacks - take a look at these examples to get started: ### App build tools and libraries - **Parcel**<br/>[styled-components](https://github.com/ben-rogerson/twin.examples/tree/master/react-styled-components) / [emotion](https://github.com/ben-rogerson/twin.examples/tree/master/react-emotion) / [emotion (ts)](https://github.com/ben-rogerson/twin.examples/tree/master/react-emotion-typescript) - **Webpack**<br/>[styled-components (ts)](https://github.com/ben-rogerson/twin.examples/tree/master/webpack-styled-components-typescript) / [emotion (ts)](https://github.com/ben-rogerson/twin.examples/tree/master/webpack-emotion-typescript) - **Preact**<br/>[styled-components](https://github.com/ben-rogerson/twin.examples/tree/master/preact-styled-components) / [emotion](https://github.com/ben-rogerson/twin.examples/tree/master/preact-emotion) / [goober](https://github.com/ben-rogerson/twin.examples/tree/master/preact-goober) - **Create React App**<br/>[styled-components](https://github.com/ben-rogerson/twin.examples/tree/master/cra-styled-components) / [emotion](https://github.com/ben-rogerson/twin.examples/tree/master/cra-emotion) - **Vite**<br/>[styled-components (ts)](https://github.com/ben-rogerson/twin.examples/tree/master/vite-styled-components-typescript) / [emotion (ts)](https://github.com/ben-rogerson/twin.examples/tree/master/vite-emotion-typescript) / [solid (ts)](https://github.com/ben-rogerson/twin.examples/tree/master/vite-solid-typescript) - **Jest / React Testing Library**<br/>[styled-components (ts) / emotion (ts)](https://github.com/ben-rogerson/twin.examples/tree/master/jest-testing-typescript) ### Advanced frameworks - **Next.js**<br/>[styled-components](https://github.com/ben-rogerson/twin.examples/tree/master/next-styled-components) / [styled-components (ts)](https://github.com/ben-rogerson/twin.examples/tree/master/next-styled-components-typescript) / [emotion](https://github.com/ben-rogerson/twin.examples/tree/master/next-emotion) / [emotion (ts)](https://github.com/ben-rogerson/twin.examples/tree/master/next-emotion-typescript) / [stitches (ts)](https://github.com/ben-rogerson/twin.examples/tree/master/next-stitches-typescript) - **T3 App**<br/>[styled-components (ts)](https://github.com/ben-rogerson/twin.examples/tree/master/t3-styled-components-typescript) / [emotion (ts)](https://github.com/ben-rogerson/twin.examples/tree/master/t3-emotion-typescript) - **Blitz.js**<br/>[emotion (ts)](https://github.com/ben-rogerson/twin.examples/tree/master/blitz-emotion-typescript) - **Gatsby**<br/>[styled-components](https://github.com/ben-rogerson/twin.examples/tree/master/gatsby-styled-components) / [emotion](https://github.com/ben-rogerson/twin.examples/tree/master/gatsby-emotion) ### Component libraries - **Storybook**<br/>[styled-components (ts)](https://github.com/ben-rogerson/twin.examples/tree/master/storybook-styled-components-typescript) / [emotion](https://github.com/ben-rogerson/twin.examples/tree/master/storybook-emotion) / [emotion (ts)](https://github.com/ben-rogerson/twin.examples/tree/master/storybook-emotion-typescript) - **yarn/npm workspaces + Next.js + shared ui components**<br/>[styled-components](https://github.com/ben-rogerson/twin.examples/tree/master/component-library-styled-components) - **Yarn workspaces + Rollup**<br/>[emotion](https://github.com/ben-rogerson/twin.examples/tree/master/component-library-emotion) - [**HeadlessUI** (ts)](https://github.com/ben-rogerson/twin.examples/tree/master/headlessui-typescript) ## Community [Drop into our Discord server](https://discord.gg/Xj6x9z7) for announcements, help and styling chat. <a href="https://discord.gg/Xj6x9z7"><img src="https://img.shields.io/discord/705884695400939552?label=discord&logo=discord" alt="Discord"></a> ## Resources - 🔥 [Docs: The prop styling guide](https://github.com/ben-rogerson/twin.macro/blob/master/docs/prop-styling-guide.md) - A must-read guide to level up on prop styling - 🔥 [Docs: The styled component guide](https://github.com/ben-rogerson/twin.macro/blob/master/docs/styled-component-guide.md) - A must-read guide on getting productive with styled components - [Docs: Options](https://github.com/ben-rogerson/twin.macro/blob/master/docs/options.md) - Learn about the features you can tweak via the twin config - [Plugin: babel-plugin-twin](https://github.com/ben-rogerson/babel-plugin-twin) - Use the tw and css props without adding an import - [Example: Advanced theming](https://github.com/ben-rogerson/twin.macro/blob/master/docs/advanced-theming.md) - Add custom theming the right way using css variables - [Example: React + Tailwind breakpoint syncing](https://gist.github.com/ben-rogerson/b4b406dffcc18ae02f8a6c8c97bb58a8) - Sync your tailwind.config.js breakpoints with react - [Helpers: Twin VSCode snippets](https://gist.github.com/ben-rogerson/c6b62508e63b3e3146350f685df2ddc9) - For devs who want to type less - [Plugins: VSCode plugins](https://github.com/ben-rogerson/twin.macro/discussions/227) - VScode plugins that work with twin - [Article: "Why I Love Tailwind" by Max Stoiber](https://mxstbr.com/thoughts/tailwind) - Max (inventor of styled-components) shares his thoughts on twin ## Special thanks This project stemmed from [babel-plugin-tailwind-components](https://github.com/bradlc/babel-plugin-tailwind-components) so a big shout out goes to [Brad Cornes](https://github.com/bradlc) for the amazing work he produced. Styling with tailwind.macro has been such a pleasure. --- [Consider donating some 🍕 if you enjoy!](https://www.buymeacoffee.com/benrogerson)

CSS Frameworks & UI Kits JavaScript Libraries & Components
8K Github Stars
nuxt-seomatic-meta
Open Source

nuxt-seomatic-meta

<h1 align="center">nuxt-seomatic-meta &nbsp; <a href="https://www.npmjs.com/package/nuxt-seomatic-meta"><img src="https://img.shields.io/npm/v/nuxt-seomatic-meta.svg" alt="NPM"></a></h1> <p align="center"> <img width="80%" src="https://i.imgur.com/BFG9Nn2.png" alt="Icon"> </p> If you're using Nuxt.js with Craft CMS headless then there's a good chance you'll be aiming for some decent SEO. A custom solution would take too much time, so a great alternative is to request the SEO data from [SEOmatic](https://plugins.craftcms.com/seomatic) via GraphQL. This module grabs the SEOmatic data and converts it to a format that Nuxt.js expects in it's [head property](https://nuxtjs.org/api/configuration-head/). ## Getting started Before starting, I'll assume you've installed [Craft (>=3.3)](https://github.com/craftcms/cms/blob/develop/CHANGELOG-v3.md#330---2019-08-27), [SEOmatic (>=3.2.28)](https://github.com/nystudio107/craft-seomatic/releases/tag/3.2.28) and enabled [Crafts GraphQL API](https://docs.craftcms.com/v3/graphql.html#getting-started). ⚠️ Note: Craft can't be in `headlessMode` - [Headless mode](https://docs.craftcms.com/v3/config/config-settings.html#headlessmode) won't work with SEOmatic as we need to match the URI which gets turned off when headlessMode is enabled. ⚠️ Note: Within `Craft > GraphQL > Schemas`, be sure to adjust the scope to the right entries in the GraphQL schema - I find it easy to forget that. 1. Install `nuxt-seomatic-meta` via yarn or npm: ```sh yarn add nuxt-seomatic-meta # or: npm install nuxt-seomatic-meta ``` 2. Add the seomatic-meta and axios plugins to your modules section in `nuxt.config.js`: ```js /* ** Nuxt.js modules */ modules: [ 'nuxt-seomatic-meta', '@nuxtjs/axios', // '@nuxtjs/dotenv', ], ``` _'@nuxtjs/axios'_: Axios is used to connect to the Craft CMS API - it's automatically installed as a dependency of `nuxt-seomatic-meta` so you'll just need to add it to the array. _'@nuxtjs/dotenv'_ (optional): To specify your GraphQL connection variables in a `.env` file then [install the nuxt dotenv module](https://github.com/nuxt-community/dotenv-module#setup). 3. Now specify the GraphQL connection settings - you have two options: a) Add the connection settings to an `.env` file in your project root (if you're using the [@nuxtjs/dotenv](https://github.com/nuxt-community/dotenv-module#setup) module): ```bash # Craft installation url BACKEND_URL=https://YOUR_DOMAIN # GraphQL api path GRAPHQL_PATH=/api # GraphQL bearer token (Not required if API is public) GRAPHQL_TOKEN=ACCESS_TOKEN_SECRET ``` b) Or add the connection settings to a new `seomaticMeta` object in `nuxt.config.js`: ```js /* ** Seomatic meta config */ seomaticMeta: { backendUrl: 'http://YOUR_DOMAIN', graphqlPath: '/api', graphqlToken: 'ACCESS_TOKEN_SECRET', }, ``` 4. Lastly, add some code to start the API request and supply the result to Nuxt's head property. This is added to your pages in `pages/*.vue`: ```js <script> export default { //... // Get Seomatic data from Craft by route async asyncData({ app, route }) { const siteId = 1 // For multi-site installs return { headData: await app.seomaticMeta(route, siteId) }; }, // Supply the data to the Nuxt head property head() { return this.headData; } }; </script> ``` ## Configuration Options can be supplied in a `seomaticMeta` object in `nuxt.config.js`: ```js seomaticMeta: { debug: true, routeRemap: [ { path: '/', getFrom: 'homepage', }, { path: 'another-route', getFrom: 'gets-meta-from-this-route-instead', }, ], backendUrl: 'http://YOUR_DOMAIN', graphqlPath: '/api', graphqlToken: 'ACCESS_TOKEN_SECRET', }, ``` | Name | Type | Default | Description | | ------------ | --------- | --------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | debug | `boolean` | `false` | Display the GraphQL data and other useful feedback in your console when using `npm run generate`. | | routeRemap | `array` | `[]` | Custom remapping of route data so you can grab the SEOmatic data from another page.<br> Eg: Your Nuxt homepage has a route of `/` but you want data from a page in Craft with a slug of `homepage`. | | backendUrl | `string` | `` | The url for your Craft installation.<br>This can also be defined in your `.env` under the key `BACKEND_URL`. | | graphqlPath | `string` | `` | The path to your GraphQL API.<br>This can also be defined in your `.env` under the key `GRAPHQL_PATH`. | | graphqlToken | `string` | `` | The token for your secured GraphQL endpoint.<br>This can also be defined in your `.env` under the key `GRAPHQL_TOKEN`. | Note: .env variables require the [dotenv module](https://github.com/nuxt-community/dotenv-module#setup). ## 🤝 Contributing Contributions, issues and feature requests are welcome!<br />Feel free to check the [issues page](http://github.com/ben-rogerson/nuxt-seomatic-meta/issues). ## Show your support Give a ⭐️ if this project helped you!

CMS Plugins & Extensions SEO Tools
32 Github Stars