Skip to content

Commit

Permalink
Replace polished dep with CSS relative color syntax and color-mix
Browse files Browse the repository at this point in the history
  • Loading branch information
askoufis committed Dec 11, 2024
1 parent 578a491 commit 93d6720
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 13 deletions.
5 changes: 5 additions & 0 deletions .changeset/few-coats-smash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'playroom': patch
---

Replace `polished` dependency with CSS relative color syntax and `color-mix`
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@
"memoize-one": "^6.0.0",
"mini-css-extract-plugin": "^2.7.2",
"parse-prop-types": "^0.3.0",
"polished": "^4.2.2",
"portfinder": "^1.0.32",
"prettier": "^2.8.1",
"prop-types": "^15.8.1",
Expand Down
10 changes: 0 additions & 10 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions src/Playroom/Toolbar/Toolbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import SettingsIcon from '../icons/SettingsIcon';
import { isMac } from '../../utils/formatting';

import { CSSTransition } from 'react-transition-group';
import { Box } from '../Box/Box';
import { colorPaletteVars } from '../sprinkles.css';

interface Props {
themes: PlayroomProps['themes'];
Expand Down Expand Up @@ -118,6 +120,16 @@ export default ({ themes: allThemes, widths: allWidths, snippets }: Props) => {
<FramesIcon />
</ToolbarItem>

<Box
style={{ backgroundColor: colorPaletteVars.background.positive }}
>
Foo
</Box>
<Box
style={{ backgroundColor: colorPaletteVars.background.critical }}
>
Foo
</Box>
<ToolbarItem
active={isPreviewOpen}
title="Preview playroom"
Expand Down
31 changes: 29 additions & 2 deletions src/Playroom/palettes.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { transparentize, mix, darken } from 'polished';

const originalPalette = {
blue0: '#e5f3ff',
blue1: '#0088ff',
Expand All @@ -22,6 +20,35 @@ const originalPalette = {
black: '#000',
};

const guard = (amount: number) => {
if (amount > 1 || amount < 0) {
throw new Error('Amount must be between 0 and 1 inclusive');
}

return amount;
};

/**
* Implementation of `transparentize` from polished but using native CSS
* @see https://polished.js.org/docs/#transparentize
*/
const transparentize = (amount: number, color: string) =>
`rgb(from ${color} r g b / calc(alpha - ${guard(amount)}))`;

/**
* Implementation of `darken` from polished but using native CSS
* @see https://polished.js.org/docs/#darken
*/
const darken = (amount: number, color: string) =>
`hsl(from ${color} h s calc(l - ${guard(amount) * 100}))`;

/**
* Implementation of `mix` from polished but using native CSS
* @see https://polished.js.org/docs/#mix
*/
const mix = (amount: number, color1: string, color2: string) =>
`color-mix(in srgb, ${color1} ${guard(amount) * 100}%, ${color2})`;

export const light = {
code: {
text: originalPalette.black,
Expand Down

0 comments on commit 93d6720

Please sign in to comment.