Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync shadcn #2877

Merged
merged 6 commits into from
Jan 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/soft-zebras-camp.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@udecode/plate-ui": minor
---

- add support for `plate-components.json` to avoid conflict with shadcn's `components.json`. If `plate-components.json` does not exist, `components.json` will be used.
- add support for custom ui dir in `components.json`: use `aliases > plate-ui`.
5 changes: 5 additions & 0 deletions apps/www/content/docs/components/changelog.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ Use the [CLI](https://platejs.org/docs/components/cli) to install the latest ver

## January 2024 #7

### January 11 #7.4

- add support for custom ui dir in `components.json`
- add support for `plate-components.json` to avoid conflict with shadcn's `components.json`

### January 9 #7.3

- `toolbar`
Expand Down
4 changes: 3 additions & 1 deletion apps/www/content/docs/components/cli.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,17 @@ The `init` command installs dependencies, adds the `cn` util, configures `tailwi
npx @udecode/plate-ui@latest init
```

You will be asked a few questions to configure `components.json`:
You will be asked a few questions to configure `plate-components.json`:

```txt showLineNumbers
Which style would you like to use? › Default
Which color would you like to use as base color? › Slate
Where is your global CSS file? › src/style/globals.css
Do you want to use CSS variables for colors? › no / yes
Are you using a custom tailwind prefix eg. tw-? (Leave blank if not) ...
Where is your tailwind.config.js located? › tailwind.config.js
Configure the import alias for components: › @/components
Configure the import alias for ui: › @/components/plate-ui
Are you using React Server Components? › no / yes
```

Expand Down
47 changes: 26 additions & 21 deletions apps/www/content/docs/components/components-json.mdx
Original file line number Diff line number Diff line change
@@ -1,31 +1,33 @@
---
title: components.json
title: plate-components.json
description: Configuration for your project.
---

The `components.json` file holds configuration for your project.
The `plate-components.json` file holds configuration for your project.

We use it to understand how your project is set up and how to generate components customized for your project.

<Callout className="mt-6">
Note: The `components.json` file is optional and **only required if you're
Note: The `plate-components.json` file is optional and **only required if you're
using the CLI** to add components to your project. If you're using the copy
and paste method, you don't need this file.
</Callout>

You can create a `components.json` file in your project by running the following command:
You can create a `plate-components.json` file in your project by running the following command:

```bash
npx @udecode/plate-ui@latest init
```

Or you could extend [shadcn's `components.json`](https://ui.shadcn.com/docs/components-json) if you don't have any conflict.

See the <Link href="/docs/components/cli">CLI section</Link> for more information.

## $schema

You can see the JSON Schema for `components.json` [here](https://platejs.org/schema.json).
You can see the JSON Schema for `plate-components.json` [here](https://platejs.org/schema.json).

```json title="components.json"
```json title="plate-components.json"
{
"$schema": "https://platejs.org/schema.json"
}
Expand All @@ -35,7 +37,7 @@ You can see the JSON Schema for `components.json` [here](https://platejs.org/sch

The style for your components. **This cannot be changed after initialization.**

```json title="components.json"
```json title="plate-components.json"
{
"style": "default"
}
Expand All @@ -51,7 +53,7 @@ See the <Link href="/docs/installation">installation section</Link> for how to s

Path to where your `tailwind.config.js` file is located.

```json title="components.json"
```json title="plate-components.json"
{
"tailwind": {
"config": "tailwind.config.js" | "tailwind.config.ts"
Expand All @@ -63,7 +65,7 @@ Path to where your `tailwind.config.js` file is located.

Path to the CSS file that imports Tailwind CSS into your project.

```json title="components.json"
```json title="plate-components.json"
{
"tailwind": {
"css": "src/styles/globals.css"
Expand All @@ -75,7 +77,7 @@ Path to the CSS file that imports Tailwind CSS into your project.

This is used to generate the default color palette for your components. **This cannot be changed after initialization.**

```json title="components.json"
```json title="plate-components.json"
{
"tailwind": {
"baseColor": "slate" | "gray" | "neutral" | "stone" | "zinc"
Expand All @@ -89,7 +91,7 @@ You can choose between using CSS variables or Tailwind CSS utility classes for t

To use utility classes for theming set `tailwind.cssVariables` to `false`. For CSS variables, set `tailwind.cssVariables` to `true`.

```json title="components.json"
```json title="plate-components.json"
{
"tailwind": {
"cssVariables": `true` | `false`
Expand All @@ -105,7 +107,7 @@ For more information, see the <Link href="/docs/theming">theming docs</Link>.

The prefix to use for your Tailwind CSS utility classes. Components will be added with this prefix.

```json title="components.json"
```json title="plate-components.json"
{
"tailwind": {
"prefix": "tw-"
Expand All @@ -119,7 +121,7 @@ Whether or not to enable support for React Server Components.

The CLI automatically adds a `use client` directive to client components when set to `true`.

```json title="components.json"
```json title="plate-components.json"
{
"rsc": `true` | `false`
}
Expand All @@ -136,26 +138,29 @@ Path aliases have to be set up in your `tsconfig.json` file.
under `paths` in your `tsconfig.json` file.
</Callout>

### aliases.utils
### aliases.components

Import alias for your utility functions.
Import alias for your components.

```json title="components.json"
```json title="plate-components.json"
{
"aliases": {
"utils": "@udecode/cn"
"components": "@/components"
}
}
```

### aliases.components

Import alias for your components.
### aliases.plate-ui

Import alias for `plate-ui` components. If not defined, uses `aliases.ui`, or `aliases.components`.

```json title="components.json"
The CLI will use this value to determine where to place your UI components. Use this config if you want to customize the installation directory for your UI components.

```json title="plate-components.json"
{
"aliases": {
"components": "@/components"
"plate-ui": "@/components/plate-ui"
}
}
```
6 changes: 4 additions & 2 deletions apps/www/content/docs/components/installation/next.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,19 @@ npx create-next-app@latest my-app --typescript --tailwind --eslint
npx @udecode/plate-ui@latest init
```

### Configure components.json
### Configure plate-components.json

You will be asked a few questions to configure `components.json`:
You will be asked a few questions to configure `plate-components.json`:

```txt showLineNumbers
Which style would you like to use? › Default
Which color would you like to use as base color? › Slate
Where is your global CSS file? › src/style/globals.css
Do you want to use CSS variables for colors? › no / yes
Are you using a custom tailwind prefix eg. tw-? (Leave blank if not) ...
Where is your tailwind.config.js located? › tailwind.config.js
Configure the import alias for components: › @/components
Configure the import alias for ui: › @/components/plate-ui
Are you using React Server Components? › no / yes
```

Expand Down
6 changes: 4 additions & 2 deletions apps/www/content/docs/components/installation/vite.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -74,17 +74,19 @@ Run the `plate-ui` init command to setup your project:
npx @udecode/plate-ui@latest init
```

### Configure components.json
### Configure plate-components.json

You will be asked a few questions to configure `components.json`:
You will be asked a few questions to configure `plate-components.json`:

```txt showLineNumbers
Which style would you like to use? › Default
Which color would you like to use as base color? › Slate
Where is your global CSS file? › › src/styles/globals.css
Do you want to use CSS variables for colors? › no / yes
Are you using a custom tailwind prefix eg. tw-? (Leave blank if not) ...
Where is your tailwind.config.js located? › tailwind.config.js
Configure the import alias for components: › @/components
Configure the import alias for ui: › @/components/plate-ui
Are you using React Server Components? › no / yes (no)
```

Expand Down
8 changes: 4 additions & 4 deletions apps/www/content/docs/components/theming.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ You can choose between using CSS variables or Tailwind CSS utility classes for t
<div className="bg-slate-950 dark:bg-white" />
```

To use utility classes for theming set `tailwind.cssVariables` to `false` in your `components.json` file.
To use utility classes for theming set `tailwind.cssVariables` to `false` in your `plate-components.json` file.

```json {8} title="components.json"
```json {8} title="plate-components.json"
{
"style": "default",
"rsc": true,
Expand All @@ -36,9 +36,9 @@ To use utility classes for theming set `tailwind.cssVariables` to `false` in you
<div className="bg-background text-foreground" />
```

To use CSS variables for theming set `tailwind.cssVariables` to `true` in your `components.json` file.
To use CSS variables for theming set `tailwind.cssVariables` to `true` in your `plate-components.json` file.

```json {8} title="components.json"
```json {8} title="plate-components.json"
{
"style": "default",
"rsc": true,
Expand Down
9 changes: 9 additions & 0 deletions apps/www/public/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
},
"cssVariables": {
"type": "boolean"
},
"prefix": {
"type": "string"
}
},
"required": ["config", "css", "baseColor", "cssVariables"]
Expand All @@ -32,6 +35,12 @@
"properties": {
"components": {
"type": "string"
},
"ui": {
"type": "string"
},
"plate-ui": {
"type": "string"
}
},
"required": ["components"]
Expand Down
11 changes: 10 additions & 1 deletion apps/www/src/components/command-menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,16 @@ export function CommandMenu({ ...props }: DialogProps) {

React.useEffect(() => {
const down = (e: KeyboardEvent) => {
if (e.key === 'k' && (e.metaKey || e.ctrlKey)) {
if ((e.key === 'k' && (e.metaKey || e.ctrlKey)) || e.key === '/') {
if (
(e.target instanceof HTMLElement && e.target.isContentEditable) ||
e.target instanceof HTMLInputElement ||
e.target instanceof HTMLTextAreaElement ||
e.target instanceof HTMLSelectElement
) {
return;
}

e.preventDefault();
setOpen((_open) => !_open);
}
Expand Down
10 changes: 10 additions & 0 deletions apps/www/src/components/mobile-nav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ export function MobileNav() {
onOpenChange={setOpen}
>
{item.title}
{item.label && (
<span className="ml-2 rounded-md bg-[#adfa1d] px-1.5 py-0.5 text-xs leading-none text-[#000000] no-underline group-hover:no-underline">
{item.label}
</span>
)}
</MobileLink>
)
);
Expand All @@ -100,6 +105,11 @@ export function MobileNav() {
className="text-muted-foreground"
>
{_item.title}
{item.label && (
<span className="ml-2 rounded-md bg-[#adfa1d] px-1.5 py-0.5 text-xs leading-none text-[#000000] no-underline group-hover:no-underline">
{item.label}
</span>
)}
</MobileLink>
) : (
_item.title
Expand Down
1 change: 1 addition & 0 deletions config/eslint/bases/unicorn.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ module.exports = {
extends: ['plugin:unicorn/recommended'],
plugins: ['unicorn'],
rules: {
'unicorn/prefer-module': 'off',
'unicorn/consistent-destructuring': 'off',
'unicorn/consistent-function-scoping': [
'error',
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/commands/add.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export const add = new Command()
logger.warn(
`Configuration is missing. Please run ${chalk.green(
`init`
)} to create a components.json file.`
)} to create a plate-components.json file.`
);
process.exit(1);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/commands/diff.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export const diff = new Command()
logger.warn(
`Configuration is missing. Please run ${chalk.green(
`init`
)} to create a components.json file.`
)} to create a plate-components.json file.`
);
process.exit(1);
}
Expand Down
14 changes: 11 additions & 3 deletions packages/cli/src/commands/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import * as z from 'zod';

import {
DEFAULT_COMPONENTS,
DEFAULT_PLATE_UI,
DEFAULT_TAILWIND_CONFIG,
DEFAULT_TAILWIND_CSS,
getConfig,
Expand Down Expand Up @@ -145,6 +146,12 @@ export async function promptForConfig(
message: `Configure the import alias for ${highlight('components')}:`,
initial: defaultConfig?.aliases['components'] ?? DEFAULT_COMPONENTS,
},
{
type: 'text',
name: 'plate-ui',
message: `Configure the import alias for ${highlight('plate-ui')}:`,
initial: defaultConfig?.aliases['plate-ui'] ?? DEFAULT_PLATE_UI,
},
{
type: 'toggle',
name: 'rsc',
Expand All @@ -169,6 +176,7 @@ export async function promptForConfig(
tsx: true,
aliases: {
components: options.components,
'plate-ui': options['plate-ui'],
},
});

Expand All @@ -177,7 +185,7 @@ export async function promptForConfig(
type: 'confirm',
name: 'proceed',
message: `Write configuration to ${highlight(
'components.json'
'plate-components.json'
)}. Proceed?`,
initial: true,
});
Expand All @@ -189,8 +197,8 @@ export async function promptForConfig(

// Write to file.
logger.info('');
const spinner = ora(`Writing components.json...`).start();
const targetPath = path.resolve(cwd, 'components.json');
const spinner = ora(`Writing plate-components.json...`).start();
const targetPath = path.resolve(cwd, 'plate-components.json');
await fs.writeFile(targetPath, JSON.stringify(config, null, 2), 'utf8');
spinner.succeed();

Expand Down
Loading