Skip to content

Commit

Permalink
feat(palette): automatically load palette when present ; add option &…
Browse files Browse the repository at this point in the history
… tests
  • Loading branch information
Tahul committed Oct 16, 2023
1 parent b83ed46 commit c7d3fa8
Show file tree
Hide file tree
Showing 28 changed files with 19,853 additions and 295 deletions.
30 changes: 20 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,38 @@
> [🕹️ Try it online](https://play.pinceau.dev)[📖 Documentation](https://pinceau.dev)
- 🪄 Fully-typed styling API inspired from the tools you already [_love_](https://stitches.dev)
- `$styled.el()`, `styled()` and `css()`
- 🦾 Typed Styling API inspired from the tools you already [_love_](https://stitches.dev)

- 🎨 Multi-layers [Design Tokens compatible](https://github.com/design-tokens/community-group) theming
- ```typescript
const Component = $styled.a<Props>({ ...componentStyle })
const className = styled({ ...scopedCss })
css({ ...globalCss })
```

- ⚡ Plug & play support for any [Vite](https://vitejs.dev)-based framework:
- [Vue](./integrations/vue), [React](./integrations/vue), [Svelte](./integrations/vue), [Nuxt](./integrations/nuxt), [Astro](./integrations/astro)
- Planned support for: [Qwik](https://qwik.builder.io), [SolidJS](https://www.solidjs.com), [Preact](https://preactjs.com), [Lit](https://lit.dev), [_yours ?_](https://github.com/Tahul/pinceau/issues)
- 🎨 Multi-layers [Design Tokens compatible](https://github.com/design-tokens/community-group) theme configuration

- 💅 Comes with everything you need to build a robust design system:
- ⚡ Plug & play support for any [Vite](https://vitejs.dev)-based framework
> [Vue](./integrations/vue), [React](./integrations/vue), [Svelte](./integrations/vue), [Nuxt](./integrations/nuxt), [Astro](./integrations/astro)
- 🪄 Comes with everything you need to build a robust design system
- Smart output engine that uses [static CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) or [CSSOM](https://developer.mozilla.org/en-US/docs/Web/API/CSS_Object_Model) when you need it
- Style colocation
- Style composition
- Responsive variants API
- Theming tokens
- Theming and local tokens
- Runtime theme swapping

- 🌐 SSR-ready with optimized hydration and no _JS/CSS_ theme duplication
- 🧱 Fully modulable, let you disable every feature you do not need but needs no configuration to start

- 🌐 SSR-ready with optimized hydration and no _JS/CSS_ style duplication

-**300+** tests covering every core packages and integrations

- 🍦 [Pinceau VSCode extension](https://marketplace.visualstudio.com/items?itemName=yaelguilloux.pinceau-vscode) for **DX Sugar**
- 🍦 [VSCode extension](https://marketplace.visualstudio.com/items?itemName=yaelguilloux.pinceau-vscode) for **DX Sugar**

> Planned support for: [Qwik](https://qwik.builder.io), [SolidJS](https://www.solidjs.com), [Preact](https://preactjs.com), [Lit](https://lit.dev), [_yours ?_](https://github.com/Tahul/pinceau/issues)
> Pinceau v1 is currently in **⚠️ beta**, feel free to report any feedback you may have in [issues](https://github.com/Tahul/pinceau/issues).
## ⚙️ Install

Expand Down
2 changes: 1 addition & 1 deletion docs/content/3.advanced/0.vite-plugin-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ That is useful if you want to listen to the Pinceau outputs.
### `buildDir`

- `string|undefined`{lang="ts"}
- `'node_modules/.vite/pinceau'`{lang="ts"}
- `'node_modules/.pinceau'`{lang="ts"}

The directory where your theme outputs will be written.

Expand Down
1 change: 1 addition & 0 deletions examples/vite-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"devDependencies": {
"@pinceau/configs": "workspace:*",
"@pinceau/react": "workspace:*",
"@pinceau/palette": "workspace:*",
"@types/node": "20.8.5",
"@types/react": "latest",
"@types/react-dom": "latest",
Expand Down
2 changes: 1 addition & 1 deletion examples/vite-react/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function App() {
return (
<div>
<header>
<TestComponent color="magenta" size="lg">
<TestComponent color="red" size="lg">
???
</TestComponent>

Expand Down
14 changes: 1 addition & 13 deletions examples/vite-react/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,16 @@ import { defineConfig } from 'vite'
import React from '@vitejs/plugin-react'
import Pinceau from '@pinceau/react/plugin'

const root = resolve('../../')

// https://vitejs.dev/config/
export default defineConfig({
plugins: [
Pinceau(
{
vue: false,
debug: 2,
style: {
excludes: [
resolve('../../packages'),
],
},
theme: {
buildDir: resolve('./node_modules/.pinceau/'),
layers: [
{
path: resolve('../../packages/palette/'),
},
],
},
}
},
),
React(),
Expand Down
1 change: 1 addition & 0 deletions examples/vite-svelte/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"devDependencies": {
"@pinceau/configs": "workspace:*",
"@pinceau/svelte": "workspace:*",
"@pinceau/palette": "workspace:*",
"@sveltejs/vite-plugin-svelte": "^2.4.6",
"svelte": "^4.2.1",
"svelte-check": "^3.5.2",
Expand Down
11 changes: 1 addition & 10 deletions examples/vite-svelte/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,11 @@ export default defineConfig({
},
plugins: [
Pinceau({
debug: 2,
style: {
excludes: [
resolve('../../packages'),
],
},
theme: {
buildDir: resolve('./node_modules/.pinceau/'),
layers: [
{
path: resolve('../../packages/palette/'),
},
],
},
}
}),
svelte(),
],
Expand Down
9 changes: 1 addition & 8 deletions examples/vite-vue/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,11 @@ export default defineConfig({
plugins: [
Vue(),
Pinceau({
debug: 2,
style: {
excludes: [
resolve('../../packages'),
],
},
theme: {
buildDir: resolve('./node_modules/.pinceau'),
layers: [
'@pinceau/palette'
],
},
}
}),
!process.env.VITEST_WORKER_ID
? Inspect({
Expand Down
2 changes: 2 additions & 0 deletions integrations/react/src/runtime/computed-styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ export function useComputedStyles(fns?: [string, ComputedStyleDefinition][], pro

const [className, setClassName] = useState<string>()

console.log(fns)

const newClassName = runtimeSheet.getRule(
computedStylesToDeclaration(
(fns || []).map(([varName, fn]) => [varName, fn(props || {})] as [string, ReturnType<ComputedStyleDefinition>]),
Expand Down
7 changes: 6 additions & 1 deletion integrations/react/src/runtime/pinceau-component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ import { createElement } from 'react'
import type { ComputedStyleDefinition, SupportedHTMLElements, Variants } from '@pinceau/style'
import { usePinceauRuntime } from './pinceau-runtime'

export function usePinceauComponent<T extends {}>(staticClass?: string | undefined, computedStyles?: [string, ComputedStyleDefinition][], variants?: Variants, type?: SupportedHTMLElements) {
export function usePinceauComponent<T extends {}>(type?: SupportedHTMLElements, staticClass?: string | undefined, computedStyles?: [string, ComputedStyleDefinition][], variants?: Variants) {
let localAttrs = {}

const component = (
props: T,
) => {
Expand All @@ -13,6 +15,7 @@ export function usePinceauComponent<T extends {}>(staticClass?: string | undefin
{
...props,
className: pinceauClasses,
...(localAttrs || {}),
},
)
}
Expand All @@ -22,5 +25,7 @@ export function usePinceauComponent<T extends {}>(staticClass?: string | undefin
return component
}

component.withAttrs = attrs => (localAttrs = attrs)

return component
}
6 changes: 1 addition & 5 deletions integrations/react/src/utils/unplugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,6 @@ export const PinceauReactPlugin: UnpluginInstance<undefined> = createUnplugin(()

transformInclude: id => transformInclude(id, ctx),

transform: async (code, id) => {
const result = await transform(code, id, suite, ctx)

return result
},
transform: async (code, id) => await transform(code, id, suite, ctx),
}
})
4 changes: 2 additions & 2 deletions integrations/vscode/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ export function activate(context: vscode.ExtensionContext) {
synchronize: {
fileEvents: [
vscode.workspace.createFileSystemWatcher('**/*/.nuxt/pinceau/index.ts'),
vscode.workspace.createFileSystemWatcher('**/*/node_modules/.vite/pinceau/index.ts'),
vscode.workspace.createFileSystemWatcher('**/*/node_modules/.pinceau/index.ts'),
vscode.workspace.createFileSystemWatcher('**/*/.nuxt/pinceau/definitions.ts'),
vscode.workspace.createFileSystemWatcher('**/*/node_modules/.vite/pinceau/definitions.ts'),
vscode.workspace.createFileSystemWatcher('**/*/node_modules/.pinceau/definitions.ts'),
],
},
}
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/utils/merger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { createDefu } from 'defu'
*/
export const merger = createDefu((obj, key, value) => {
if (Array.isArray(obj[key]) && Array.isArray(value)) {
(obj as any)[key] = value // Array.from(new Set([...obj[key], ...value]))
(obj as any)[key] = value
return true
}
})
1 change: 1 addition & 0 deletions packages/core/src/utils/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export function getDefaultOptions(): { [key in keyof PinceauUserOptions]: any }
definitions: true,
schema: true,
imports: true,
palette: true,
}

const style: PinceauUserOptions['style'] = {
Expand Down
3 changes: 2 additions & 1 deletion packages/integration/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
"@pinceau/runtime": "workspace:*",
"@pinceau/stringify": "workspace:*",
"@pinceau/style": "workspace:*",
"@pinceau/theme": "workspace:*"
"@pinceau/theme": "workspace:*",
"@pinceau/palette": "workspace:*"
},
"devDependencies": {
"@pinceau/configs": "workspace:*"
Expand Down
9 changes: 0 additions & 9 deletions packages/palette/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,6 @@
},
"devDependencies": {
"@pinceau/configs": "workspace:*",
"@pinceau/core": "workspace:*",
"@pinceau/runtime": "workspace:*",
"@pinceau/style": "workspace:*",
"@pinceau/theme": "workspace:*",
"@pinceau/vue": "workspace:*",
"@pinceau/svelte": "workspace:*",
"@pinceau/react": "workspace:*",
"@pinceau/astro": "workspace:*",
"pinceau": "workspace:*",
"vite": "^4.4.11"
}
}
12 changes: 6 additions & 6 deletions packages/palette/vite.config.full.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import path from 'node:path'
import fs from 'node:fs'
import { createResolver } from '@nuxt/kit'
import { defineConfig } from 'vite'
import Pinceau from 'pinceau/plugin'
import { getPinceauContext } from '@pinceau/core/utils'
import { createReactPlugin } from '@pinceau/react/utils'
import { createVuePlugin } from '@pinceau/vue/utils'
import { createSveltePlugin } from '@pinceau/svelte/utils'
import type { PinceauContext } from '@pinceau/core'
import Pinceau from '../../integrations/pinceau/src/plugin'
import { getPinceauContext } from '../../packages/core/src/utils'
import { createReactPlugin } from '../../integrations/react/src/utils'
import { createVuePlugin } from '../../integrations/vue/src/utils'
import { createSveltePlugin } from '../../integrations/svelte/src/utils'
import type { PinceauContext } from '../../packages/core/src'

let ctx: PinceauContext

Expand Down
4 changes: 2 additions & 2 deletions packages/palette/vite.config.react.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import path from 'node:path'
import { defineConfig } from 'vite'
import Pinceau from 'pinceau/plugin'
import { PinceauReactPlugin } from '@pinceau/react/utils'
import Pinceau from '../../integrations/pinceau/src/plugin'
import { PinceauReactPlugin } from '../../integrations/react/src/utils'

export default defineConfig({
plugins: [
Expand Down
4 changes: 2 additions & 2 deletions packages/palette/vite.config.svelte.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import path from 'node:path'
import { defineConfig } from 'vite'
import Pinceau from 'pinceau/plugin'
import { PinceauSveltePlugin } from '@pinceau/svelte/utils'
import Pinceau from '../../integrations/pinceau/src/plugin'
import { PinceauSveltePlugin } from '../../integrations/svelte/src/utils'

export default defineConfig({
plugins: [
Expand Down
4 changes: 2 additions & 2 deletions packages/palette/vite.config.vue.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import path from 'node:path'
import { defineConfig } from 'vite'
import Pinceau from 'pinceau/plugin'
import { PinceauVuePlugin } from '@pinceau/vue/utils'
import Pinceau from '../../integrations/pinceau/src/plugin'
import { PinceauVuePlugin } from '../../integrations/vue/src/utils'

export default defineConfig({
plugins: [
Expand Down
3 changes: 3 additions & 0 deletions packages/theme/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ declare module '@pinceau/core' {
}

interface PinceauExtendedContext {
/**
* $theme() function for build context.
*/
$theme: ThemeFunction

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/theme/src/types/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export interface ReservedConfigKeys {
* Theme generation output.
*/
export interface ThemeGenerationOutput {
buildDir: string | undefined
buildDir: string | false | undefined
theme: Theme<PinceauTheme>
outputs: VirtualOutputs
}
Expand Down
7 changes: 6 additions & 1 deletion packages/theme/src/types/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export interface PinceauThemeOptions {
*
* If set to `false`, generation will not output anything on filesystem.
*/
buildDir: string | undefined
buildDir: string | undefined | false

/**
* Imports the default CSS reset in the project.
Expand Down Expand Up @@ -114,4 +114,9 @@ export interface PinceauThemeOptions {
* Support for definitions.ts ; improving experience for Pinceau IntelliSense.
*/
definitions: boolean

/**
* Inject `@pinceau/palette` automatically
*/
palette: boolean
}
Loading

0 comments on commit c7d3fa8

Please sign in to comment.