Skip to content

Commit a5283f4

Browse files
Version Packages (#22)
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent 9dcd8eb commit a5283f4

File tree

4 files changed

+148
-8
lines changed

4 files changed

+148
-8
lines changed

.changeset/fuzzy-flowers-relax.md

-7
This file was deleted.

src/tailwindcss-oklch/CHANGELOG.md

+8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# @alexaka1/tailwindcss-oklch
22

3+
## 0.0.4
4+
5+
### Patch Changes
6+
7+
- 9dcd8eb: Revert min-max contrast
8+
9+
It is causing problems now. This now brings this package back in line with upstreams `0.0.1` release.
10+
311
## 0.0.3
412

513
### Patch Changes

src/tailwindcss-oklch/README.md

+139
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
[![NPM Version](https://img.shields.io/npm/v/%40alexaka1%2Ftailwindcss-oklch)](https://www.npmjs.com/package/@alexaka1/tailwindcss-oklch)
2+
3+
# Tailwind OKLCH
4+
5+
view on: [npm](https://www.npmjs.com/package/@alexaka1/tailwindcss-oklch) - [GitHub](https://github.com/alexaka1/tailwindcss-oklch)
6+
7+
This repo was cloned from [Martijn Cuppens's tailwindcss-oklch](https://github.com/MartijnCuppens/tailwindcss-oklch). Special thanks to Martijn for creating this plugin.
8+
9+
Brings OKLCH to Tailwind and introduces these helpful utilities:
10+
11+
- Contrast utilities that automatically calculate the contrast color (black/white) of any color in CSS.
12+
- Match utilities that will match the color of a property with another property (e.g. outline color matches the background color), with support for opacity modifiers.
13+
- Lightness offset utilities that darken or lighten colors (e.g. on hover).
14+
15+
You don't need to change your theme colors, since this plugin uses color.js to convert all existing colors.
16+
17+
## Installation
18+
19+
To use this package, install it via npm:
20+
21+
```shell
22+
npm install tailwindcss-oklch
23+
```
24+
25+
Then, enable the plugin in your Tailwind config:
26+
27+
```js
28+
/** @type {import('tailwindcss').Config} */
29+
module.exports = {
30+
plugins: [require('@alexaka1/tailwindcss-oklch')()],
31+
};
32+
```
33+
The plugin returns a function in order to allow you to change the default values.
34+
35+
## Features
36+
37+
### Contrast utilities
38+
39+
The `text-bg-contrast` class added to an element with the `bg-blue-500` class will set the text color to the contrast color (white or black) of the blue button. If the color of the button changes lightness over time, the contrast color will be recalculated in CSS. Opacity modifiers can be added to change the opacity of the color you're setting. Examples:
40+
41+
- `text-bg-contrast` sets the text color to the contrast color of the background color.
42+
- `text-border-contrast` sets the text color to the contrast color of the border color.
43+
- `bg-border-contrast` sets the background color to the contrast color of the border color.
44+
- `text-bg-contrast/50` sets the text color to the contrast color of the background color with an opacity of 50%.
45+
- `bg-border-contrast/50` sets the background color to the contrast color of the border color with an opacity of 50%.
46+
47+
### Match utilities
48+
49+
The `text-border` class sets the text color to the same color as the border of the element. Other examples:
50+
51+
- `border-text` sets the border color to the text color. The difference with `border-current` is the ability to set opacity or change lightness with additional classes.
52+
- `border-text/50` sets the border color to the text color with an opacity of 50%.
53+
54+
### Lightness offset
55+
56+
The `text-lightness-offset-10` increases the lightness of the text with 10%. Other examples:
57+
58+
- `hover:-bg-lightness-offset-10` darkens the background on hover with 10%.
59+
60+
## Configuration
61+
62+
If you prefer to change the threshold when the contrast color switches to black or white, you can adjust the value of `contrastThreshold`. This value should be somewhere between `0` and `1`. The higher the number, the more likely white will be chosen as the contrast color. While I was working on this plugin, I noticed that a contrast threshold of `.6` looked better on different screens than `.5`, since dark colors seem to have lesser contrast then lighter colors in reality.
63+
64+
If you're looking for contrast colors beyond just black and white, and you'd like a hint of hue to be present in the contrasting shade, consider modifying the `minContrastLightness` parameter to introduce some color to the darker tones. Simultaneously, you can reduce the `maxContrastLightness` setting to infuse a touch of hue into the lighter shades of white.
65+
66+
Precision was added since color.js uses floats to calculate the OKLCH values, which can result in long numbers. Defaults to `6`.
67+
68+
```js
69+
/** @type {import('tailwindcss').Config} */
70+
module.exports = {
71+
plugins: [
72+
require('@alexaka1/tailwindcss-oklch')({
73+
contrastThreshold: 0.5,
74+
precision: 8,
75+
minContrastLightness: 0,
76+
maxContrastLightness: 1,
77+
}),
78+
],
79+
};
80+
```
81+
82+
## Demo
83+
84+
[View the demo site](https://tailwind-oklch.netlify.app).
85+
86+
## Named colors
87+
88+
In case you prefer named color names, you can add them in your Tailwind config. For example, if you want to use the Bootstrap colors:
89+
90+
```js
91+
/** @type {import('tailwindcss').Config} */
92+
module.exports = {
93+
theme: {
94+
extend: {
95+
colors: {
96+
primary: '#0d6efd',
97+
secondary: '#6c757d',
98+
success: '#198754',
99+
danger: '#dc3545',
100+
warning: '#ffc107',
101+
info: '#0dcaf0',
102+
light: '#f8f9fa',
103+
dark: '#212529',
104+
},
105+
},
106+
},
107+
};
108+
```
109+
110+
## Custom properties / CSS variables support
111+
112+
```js
113+
/** @type {import('tailwindcss').Config} */
114+
module.exports = {
115+
theme: {
116+
extend: {
117+
colors: {
118+
primary: `oklch(var(--color-primary-l) var(--color-primary-c) var(--color-primary-h) / <alpha-value>)`,
119+
secondary: `oklch(var(--color-secondary-l) var(--color-secondary-c) var(--color-secondary-h) / <alpha-value>)`,
120+
success: `oklch(var(--color-success-l) var(--color-success-c) var(--color-success-h) / <alpha-value>)`,
121+
warning: `oklch(var(--color-warning-l) var(--color-warning-c) var(--color-warning-h) / <alpha-value>)`,
122+
danger: `oklch(var(--color-danger-l) var(--color-danger-c) var(--color-danger-h) / <alpha-value>)`,
123+
},
124+
},
125+
},
126+
};
127+
```
128+
129+
You can later on change the colors without recompiling by setting the LCH values. You can use [oklch.com](https://oklch.com) (web based) or [colorjs.io](https://colorjs.io) (javascript library) to convert colors. Make sure to use decimals instead of percentages for the lightness, since these are needed to calculate contrast colors.
130+
131+
```css
132+
@layer base {
133+
:root {
134+
--color-primary-l: 0.32;
135+
--color-primary-c: 0.1;
136+
--color-primary-h: 150;
137+
}
138+
}
139+
```

src/tailwindcss-oklch/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@alexaka1/tailwindcss-oklch",
3-
"version": "0.0.3",
3+
"version": "0.0.4",
44
"private": false,
55
"description": "Bring OKLCH colors to tailwind and introduces handy color utilities",
66
"repository": "https://github.com/alexaka1/tailwindcss-oklch",

0 commit comments

Comments
 (0)