@lform/lwind v2.0.9
Lwind - Lform Tailwind Setup
The Lwind frontend styling system is designed to use as many Tailwind default-approaches as possible while also allowing for the flexibility required to implement designs produced using the Lform design system. The package is lightweight, comprised of a starting Tailwind config and a handful of PostCSS plugins.
- Requires Tailwind 3.4.0+
Resources
- Tailwind Documentation
- PostCSS Plugins - No longer used directly, all plugins from this package have been included in this package as the PostCSS package is no longer updated, it was just a wrapper for those packages.
- TailWind UI KIts - For reference for building components
Installation
Adding the Lwind system to a project is relatively straight forward:
- Run
npm i @lform/lwind Included in the package is an example starting PCSS file
css/main.example.pcss, copy this into your project's CSS root and name it accordingly:- https://github.com/lform/lwind/blob/master/css/main.example.pcss
- NOTE: To customize or override any of the Lwind pcss files, just copy the file in question from the package or create a new one in the appropriate directory, and adjust the path accordingly in your
main.pcss(or however you named the file). You can also use the components that are needed, and disable the others.
Create or update the
postcss.config.jsfile based on the package version:- https://github.com/lform/lwind/blob/master/postcss.config.js
- NOTE: Some build systems will have an alternative method of loading PostCSS plugins, you will need to add the same entries as the
postcss.config.jsto that system, using its method / format.
Copy the
tailwind.config.jsfile from the package into your project:Update the
tailwind.config.jsto match your project's design specifications.- Run the build system to confirm that everything is working.
The following
package.jsonscripts can be added if there is no build system (adjust the paths accordingly):"scripts": { "dev": "npx tailwindcss -i ./css/main.pcss -o ./dist/app.css", "watch": "npx tailwindcss -i ./css/main.pcss -o ./dist/app.css --watch", "prod": "NODE_ENV=production npx tailwindcss -i ./css/main.pcss -o ./dist/app.min.css --minify" }
Building
The following scripts are available in the package.json file, if the project uses a build system, the commands may be different.- npm run dev - Builds development version of tailwind file
npm run watch- Builds development version of tailwind file and watches filesnpm run prod- Builds development version of tailwind file
Included PostCSS Plugins
The following PostCSS plugins are used by default:
- autoprefixer - Autoprefixes CSS for browser compatibility
- postcss-advanced-variables - Used to add SCSS-style variables in PCSS, has more advanced functionality than CSS variables.
- postcss-atroot - Used to add
@at-rootfunctionality to PCSS, bubbling nested styling up to the root-level selectors. - postcss-extend-rule - Used to add SCSS-style
@extendfunctionality to PCSS, allowing for the extension of existing classes. - postcss-import - Used to import other PCSS / CSS files.
- tailwindcss/nesting - Wraps
postcss-nestedand acts as a compatibility layer to make sure your nesting plugin of choice properly understands custom syntax like@applyand@screen.
Recommend Plugins
The following PostCSS plugins are recommend depending on your needs:
- postcss-rem - Used to convert pixel values to rem, adds a
rem-convert()function that can be invoked in PCSS.pxmust be specified, or it will not function, egwidth: rem-convert(100px).
PostCSS Imports & Overriding Lwind
You can override the Lwind CSS by adding a file with the same path & filename in the project's PCSS directory and adjusting the @import statement in the main.pcss file.
Tailwind Config
Tailwind Plugins
- @tailwindcss/forms - Used to provide default baseline form styling
Breakpoints
The default breakpoints included in Tailwind are used.
Spacing / Gaps
- Designs are implemented using a base spacing sizing of 8 pixels.
- This is Tailwind's default spacing system, refer to the documentation as necessary.
Colors
Main colors are named following a
primary,secondary,tertiarylogic for the main brand colors.- Each has a
lightanddark(up-shade / down-shade) version - Each has a
fgversion for the color to use for foreground text on a background with this color, eg buttons
- Each has a
Secondary colors are added as numeric values to the
accentslist, egaccent-1. This allows for as many accents to be added as necessary to accommodate a design.- Greys are labeled using Tailwind's numbering system,
100,300,500,700,900are included by default. - Black & whites are defined in the
blackandwhitekeys, as well as their transparent versions equivalentswhite-transparentandblack-transparent - Feedback colors from forms / interactions are specified in the
success,warning, anderrorcolors - Social media brand colors are defined in the
socialkeys
Typography
Fonts available
There are 3 types of fonts in Lwind:
font-body- The body font used on the site by defaultfont-header- The main header fontfont-subheader- Usually used for small text items in a utility context, eg blog post dates
Font scaling
The font-scaling system uses Modular Scale instead of Tailwind's default
- Base is
16pxwith1.125xscaling - The scale included with Lwind goes from
-3to12 Below are the scales, or you refer to the font scale reference for the full list:
-text-ms-3= 11px-text-ms-2= 12px-text-ms-1= 14pxtext-ms-0= 16pxtext-ms-1= 18pxtext-ms-2= 20pxtext-ms-3= 22pxtext-ms-4= 25pxtext-ms-5= 28pxtext-ms-6= 32pxtext-ms-7= 36pxtext-ms-8= 41pxtext-ms-9= 46pxtext-ms-10= 51pxtext-ms-11= 58pxtext-ms-12= 65pxtext-ms-13= 73px
Header and subheader utility classes
Modular scale header utility classes have been included that include the header font with a default line-height of 1.2. Headers with default line-heights will appear too spaced out between the lines, especially at larger font sizes.
Header Classes
-h-ms-3= 11px-h-ms-2= 12px-h-ms-1= 14pxh-ms= 16pxh-ms-1= 18pxh-ms-2= 20pxh-ms-3= 22pxh-ms-4= 25pxh-ms-5= 28pxh-ms-6= 32pxh-ms-7= 36pxh-ms-8= 41pxh-ms-9= 46pxh-ms-10= 51pxh-ms-11= 58pxh-ms-12= 65pxh-ms-13= 73px
Subheader Classes
Subheaders are generally smaller in size, their available classes are as follows:
-sh-ms-3= 11px-sh-ms-2= 12px-sh-ms-1= 14pxsh-ms= 16pxsh-ms-1= 18pxsh-ms-2= 20px
Header Line Heights
By default, headers are set to 1.25 line-height as larger fonts can appear overly spaced out vertically. To override this, extend lineHeight with a header value in the Tailwind config file.
Richtext
A custom rich-text implementation is used for all rich-text areas by adding a rich-text class to any area with rich text. The rich text settings can be found in the tailwind config file.
Tailwind Utilities & Components
Buttons
Button classes are baked into Lwind and can be invoked with the following options. Buttons use the baseclass and modifier syntax.
Colors
button- The default button, uses theprimarycolor as its background andprimary-fgas the text colorbutton-secondary- The secondary color button, uses thesecondarycolor as its background andsecondary-fgas the text colorbutton-tertiary- The tertiary color button, uses thetertiarycolor as its background andtertiary-fgas the text color
Sizing
button-xsbutton-smbutton- Default sizebutton-lgbutton-xl
Examples
- Default button, small:
.button .button-sm - Secondary color button, large:
.button .button-secondary .button-sm
Containers
Tailwind's default containers are disabled in favor of a fluid container system. There are five container sizes that match the default breakpoint sizes.
- Containers are auto-centered with
margin-left&margin-rightset toauto. - They also have a default padding of
1.5rem. - Container widths & padding can be configured in the Tailwind config under the
containerssection - If a class of
px-0is added to a container, the padding will be disabled - If a class of
mx-0is added to a container, the auto-centering margin will be disabled.
Classes & Default Sizes
container- Max of1536pxcontainer-2xl- Max of1536pxcontainer-xl- Max of1280pxcontainer-lg- Max of1024pxcontainer-md- Max of768pxcontainer-sm- Max of640px
Flex Grid
CSS Grid has a limitation in that it does not support centering columns or aligning them outside of the grid structure. This issue is addressed by using a Flex-based grid, which creates a full-width grid with a specified number of columns. In a Flex Grid, any remaining columns at the bottom can be centered effectively.
- Use the class
flex-gridto implement a flex grid. - Flex Grid defaults to a single column. To change this, use
flex-grid-cols-{n}, replacing{n}with the desired number of columns (1 to 10). - Adjust horizontal spacing between Flex Grid items with
flex-grid-gap-{n}, using any number from the Tailwind default spacing scale. The maximum gap is12(48px). For larger gaps, add custom classes. - Flex Grid is fully responsive. Use
sm:,md:, andlg:prefixes withflex-grid-cols-{n}orflex-grid-gap-{n}for responsive layouts. - For vertical spacing, use Tailwind's native
gap-y-{n}since Flex Grid, powered by Flexbox, does not add vertical spacing by default. - IMPORTANT: Avoid using
margin-leftormargin-righton elements withflex-grid, as it disrupts the grid layout. Instead, apply margins to a container element.
Classes & Sizing
Base Class
flex-grid
Column Classes
flex-grid-cols-1flex-grid-cols-2flex-grid-cols-3flex-grid-cols-4flex-grid-cols-5flex-grid-cols-6flex-grid-cols-7flex-grid-cols-8flex-grid-cols-9flex-grid-cols-10
Gap Classes
flex-grid-gap-0.5= 2pxflex-grid-gap-1= 4pxflex-grid-gap-1.5= 6pxflex-grid-gap-2= 8pxflex-grid-gap-2.5= 10pxflex-grid-gap-3= 12pxflex-grid-gap-3.5= 14pxflex-grid-gap-4= 16pxflex-grid-gap-5= 20pxflex-grid-gap-6= 24pxflex-grid-gap-7= 28pxflex-grid-gap-8= 32pxflex-grid-gap-9= 36pxflex-grid-gap-10= 40pxflex-grid-gap-11= 44pxflex-grid-gap-12= 48px
Example Usage
<div class="flex-grid flex-grid-cols-2 md:flex-grid-cols-3 flex-grid-gap-2">
<!-- A 3 column flex grid with an 8 pixel gap, 2 columns on tablet -->
</div>1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago