Skip to content

Commit

Permalink
feat: make Form.SelectTrigger more flexible (#634)
Browse files Browse the repository at this point in the history
  • Loading branch information
huntabyte authored Jan 12, 2024
1 parent 1d119d9 commit d48d69f
Show file tree
Hide file tree
Showing 343 changed files with 911 additions and 2,764 deletions.
3 changes: 1 addition & 2 deletions apps/www/.eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ module.exports = {
"warn",
{
argsIgnorePattern: "^_",
varsIgnorePattern:
"^\\$\\$(Props|Events|Slots|Generic)$"
varsIgnorePattern: "^\\$\\$(Props|Events|Slots|Generic)$"
}
]
}
Expand Down
2 changes: 1 addition & 1 deletion apps/www/.prettierrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"useTabs": true,
"singleQuote": false,
"trailingComma": "none",
"printWidth": 80,
"printWidth": 100,
"endOfLine": "lf",
"plugins": ["prettier-plugin-svelte"],
"pluginSearchDirs": false,
Expand Down
25 changes: 5 additions & 20 deletions apps/www/mdsvex.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@ const __dirname = fileURLToPath(new URL(".", import.meta.url));
/** @type {import('mdsvex').MdsvexOptions} */
export const mdsvexOptions = {
extensions: [".md"],
layout: path.resolve(
__dirname,
"./src/lib/components/docs/mdsvex/mdsvex.svelte"
),
layout: path.resolve(__dirname, "./src/lib/components/docs/mdsvex/mdsvex.svelte"),
smartypants: {
quotes: false,
ellipses: false,
Expand All @@ -45,10 +42,7 @@ export const mdsvexOptions = {
const match = codeEl.data?.meta.match(regex);
if (match) {
node.__event__ = match ? match[1] : null;
codeEl.data.meta = codeEl.data.meta.replace(
regex,
""
);
codeEl.data.meta = codeEl.data.meta.replace(regex, "");
}
}

Expand All @@ -63,10 +57,7 @@ export const mdsvexOptions = {
rehypePrettyCode,
{
theme: JSON.parse(
fs.readFileSync(
path.resolve(__dirname, "./other/themes/dark.json"),
"utf-8"
)
fs.readFileSync(path.resolve(__dirname, "./other/themes/dark.json"), "utf-8")
),
onVisitLine(node) {
if (node.children.length === 0) {
Expand Down Expand Up @@ -102,10 +93,7 @@ export function rehypeComponentExample() {
return async (tree) => {
const nameRegex = /name="([^"]+)"/;
visit(tree, (node, index, parent) => {
if (
node?.type === "raw" &&
node?.value?.startsWith("<ComponentPreview")
) {
if (node?.type === "raw" && node?.value?.startsWith("<ComponentPreview")) {
const match = node.value.match(nameRegex);
const name = match ? match[1] : null;

Expand Down Expand Up @@ -190,10 +178,7 @@ function rehypeComponentPreToPre() {
// Replace `Component.pre` tags with `pre` tags.
// This is a workaround to use rehype-pretty-code along with custom mdsvex components.
visit(tree, (node) => {
if (
node?.type === "element" &&
node?.tagName === "Components.pre"
) {
if (node?.type === "element" && node?.tagName === "Components.pre") {
node.tagName = "pre";
}

Expand Down
5 changes: 1 addition & 4 deletions apps/www/other/rehype-component-example.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@ export function rehypeComponentExample() {
return async (tree) => {
const nameRegex = /name="([^"]+)"/;
visit(tree, (node, index, parent) => {
if (
node?.type === "raw" &&
node?.value?.startsWith("<ComponentExample")
) {
if (node?.type === "raw" && node?.value?.startsWith("<ComponentExample")) {
const match = node.value.match(nameRegex);
const name = match ? match[1] : null;

Expand Down
48 changes: 10 additions & 38 deletions apps/www/scripts/build-registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,7 @@ for (const style of styles) {
continue;
}

const resolveFiles = item.files.map(
(file) => `../src/lib/registry/${style.name}/${file}`
);
const resolveFiles = item.files.map((file) => `../src/lib/registry/${style.name}/${file}`);

const type = item.type.split(":")[1];
index += `
Expand Down Expand Up @@ -113,18 +111,13 @@ for (const style of styles) {
// Build registry/styles/index.json.
// ----------------------------------------------------------------------------
const stylesJson = JSON.stringify(styles, null, 2);
fs.writeFileSync(
path.join(REGISTRY_PATH, "styles/index.json"),
stylesJson,
"utf8"
);
fs.writeFileSync(path.join(REGISTRY_PATH, "styles/index.json"), stylesJson, "utf8");

// ----------------------------------------------------------------------------
// Build registry/index.json.
// ----------------------------------------------------------------------------
const names = result.data.filter(
(item) =>
item.type === "components:ui" && !REGISTRY_IGNORE.includes(item.name)
(item) => item.type === "components:ui" && !REGISTRY_IGNORE.includes(item.name)
);
const registryJson = JSON.stringify(names, null, 2);
rimraf.sync(path.join(REGISTRY_PATH, "index.json"));
Expand All @@ -150,29 +143,17 @@ for (const [color, value] of Object.entries(colors)) {
if (Array.isArray(value)) {
colorsData[color] = value.map((item) => ({
...item,
rgbChannel: item.rgb.replace(
/^rgb\((\d+),(\d+),(\d+)\)$/,
"$1 $2 $3"
),
hslChannel: item.hsl.replace(
/^hsl\(([\d.]+),([\d.]+%),([\d.]+%)\)$/,
"$1 $2 $3"
)
rgbChannel: item.rgb.replace(/^rgb\((\d+),(\d+),(\d+)\)$/, "$1 $2 $3"),
hslChannel: item.hsl.replace(/^hsl\(([\d.]+),([\d.]+%),([\d.]+%)\)$/, "$1 $2 $3")
}));
continue;
}

if (typeof value === "object") {
colorsData[color] = {
...value,
rgbChannel: value.rgb.replace(
/^rgb\((\d+),(\d+),(\d+)\)$/,
"$1 $2 $3"
),
hslChannel: value.hsl.replace(
/^hsl\(([\d.]+),([\d.]+%),([\d.]+%)\)$/,
"$1 $2 $3"
)
rgbChannel: value.rgb.replace(/^rgb\((\d+),(\d+),(\d+)\)$/, "$1 $2 $3"),
hslChannel: value.hsl.replace(/^hsl\(([\d.]+),([\d.]+%),([\d.]+%)\)$/, "$1 $2 $3")
};
continue;
}
Expand Down Expand Up @@ -281,17 +262,12 @@ for (const baseColor of ["slate", "gray", "zinc", "neutral", "stone", "lime"]) {
base["cssVars"][mode] = {};
for (const [key, value] of Object.entries(values)) {
if (typeof value === "string") {
const resolvedColor = value.replace(
/{{base}}-/g,
`${baseColor}-`
);
const resolvedColor = value.replace(/{{base}}-/g, `${baseColor}-`);
base["inlineColors"][mode][key] = resolvedColor;

const [resolvedBase, scale] = resolvedColor.split("-");
const color = scale
? colorsData[resolvedBase].find(
(item: any) => item.scale === parseInt(scale)
)
? colorsData[resolvedBase].find((item: any) => item.scale === parseInt(scale))
: colorsData[resolvedBase];
if (color) {
base["cssVars"][mode][key] = color.hslChannel;
Expand Down Expand Up @@ -391,10 +367,6 @@ for (const theme of themes) {
);
}

fs.writeFileSync(
path.join(REGISTRY_PATH, `themes.css`),
themeCSS.join("\n"),
"utf8"
);
fs.writeFileSync(path.join(REGISTRY_PATH, `themes.css`), themeCSS.join("\n"), "utf8");

console.log("✅ Done!");
13 changes: 5 additions & 8 deletions apps/www/scripts/registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,9 @@ async function crawlExample(rootPath: string) {
if (dirent.isFile() && dirent.name.endsWith(".svelte")) {
const [name] = dirent.name.split(".svelte");
const file_path = join("example", dirent.name);
const { dependencies, registryDependencies } =
await getDependencies(join(rootPath, dirent.name));
const { dependencies, registryDependencies } = await getDependencies(
join(rootPath, dirent.name)
);

exampleRegistry.push({
name,
Expand Down Expand Up @@ -116,13 +117,9 @@ async function buildUIRegistry(componentPath: string, componentName: string) {
const deps = await getDependencies(join(componentPath, dirent.name));

deps.dependencies.forEach((dep) => dependencies.add(dep));
REQUIRED_COMPONENT_DEPS.get(componentName)?.forEach((dep) =>
dependencies.add(dep)
);
REQUIRED_COMPONENT_DEPS.get(componentName)?.forEach((dep) => dependencies.add(dep));

deps.registryDependencies.forEach((dep) =>
registryDependencies.add(dep)
);
deps.registryDependencies.forEach((dep) => registryDependencies.add(dep));
}

return {
Expand Down
5 changes: 1 addition & 4 deletions apps/www/src/app.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@
data-sveltekit-preload-data="hover"
class="min-h-screen bg-background antialiased font-sans"
>
<div
style="display: contents"
class="relative flex min-h-screen flex-col"
>
<div style="display: contents" class="relative flex min-h-screen flex-col">
%sveltekit.body%
</div>
</body>
Expand Down
4 changes: 1 addition & 3 deletions apps/www/src/lib/components/docs/announcement.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
>
🎉 <Separator class="mx-2 h-4" orientation="vertical" />{" "}
<span class="sm:hidden">New components and more.</span>
<span class="hidden sm:inline">
New components, cli updates and more.
</span>
<span class="hidden sm:inline"> New components, cli updates and more. </span>
<Icons.arrowRight class="ml-1 h-4 w-4" />
</a>
7 changes: 2 additions & 5 deletions apps/www/src/lib/components/docs/charts/bar.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,7 @@
x="57"
y="-4"
fill="#888888"
text-anchor="end"
><tspan x="36" dy="0.355em">${tick}</tspan></text
text-anchor="end"><tspan x="36" dy="0.355em">${tick}</tspan></text
>
</g>
{/each}
Expand All @@ -112,9 +111,7 @@
fill="#888888"
text-anchor="middle"
><tspan x={barWidth / 2} dy="0.71em"
>{width > 380
? point.name
: formatMobile(point.name)}</tspan
>{width > 380 ? point.name : formatMobile(point.name)}</tspan
></text
>
</g>
Expand Down
6 changes: 1 addition & 5 deletions apps/www/src/lib/components/docs/code-block-wrapper.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,7 @@
)}
>
<Collapsible.Trigger asChild let:builder>
<Button
variant="secondary"
builders={[builder]}
class="h-8 text-xs"
>
<Button variant="secondary" builders={[builder]} class="h-8 text-xs">
{open ? "Collapse" : expandButtonTitle}
</Button>
</Collapsible.Trigger>
Expand Down
19 changes: 4 additions & 15 deletions apps/www/src/lib/components/docs/command-menu.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,7 @@
navItem.href && goto(navItem.href);
})}
>
<div
class="mr-2 flex h-4 w-4 items-center justify-center"
>
<div class="mr-2 flex h-4 w-4 items-center justify-center">
<Circle class="h-3 w-3" />
</div>
{navItem.title}
Expand All @@ -89,24 +87,15 @@
{/each}
<Command.Separator />
<Command.Group heading="Theme">
<Command.Item
value="light"
onSelect={() => runCommand(() => setMode("light"))}
>
<Command.Item value="light" onSelect={() => runCommand(() => setMode("light"))}>
<Sun class="mr-2 h-4 w-4" />
Light
</Command.Item>
<Command.Item
value="dark"
onSelect={() => runCommand(() => setMode("dark"))}
>
<Command.Item value="dark" onSelect={() => runCommand(() => setMode("dark"))}>
<Moon class="mr-2 h-4 w-4" />
Dark
</Command.Item>
<Command.Item
value="system"
onSelect={() => runCommand(() => resetMode())}
>
<Command.Item value="system" onSelect={() => runCommand(() => resetMode())}>
<Laptop class="mr-2 h-4 w-4" />
System
</Command.Item>
Expand Down
9 changes: 2 additions & 7 deletions apps/www/src/lib/components/docs/component-example.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,10 @@
export let align: "start" | "center" | "end" = "center";
</script>

<div
class={cn("group relative my-4 flex flex-col space-y-2", className)}
{...$$restProps}
>
<div class={cn("group relative my-4 flex flex-col space-y-2", className)} {...$$restProps}>
<Tabs.Root value="preview" class="relative mr-auto w-full">
<div class="flex items-center justify-between pb-3">
<Tabs.List
class="w-full justify-start rounded-none border-b bg-transparent p-0"
>
<Tabs.List class="w-full justify-start rounded-none border-b bg-transparent p-0">
<Tabs.Trigger
value="preview"
class="relative rounded-none border-b-2 border-b-transparent bg-transparent px-4 pb-3 pt-2 font-semibold text-muted-foreground shadow-none transition-none data-[state=active]:border-b-primary data-[state=active]:text-foreground data-[state=active]:shadow-none"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@
export { className as class };
</script>

<div
class={cn("group relative my-4 flex flex-col space-y-2", className)}
{...$$restProps}
>
<div class={cn("group relative my-4 flex flex-col space-y-2", className)} {...$$restProps}>
<div class="relative mr-auto w-full">
<div class="relative rounded-md border">
<div class="flex items-center justify-between p-4">
Expand Down
17 changes: 4 additions & 13 deletions apps/www/src/lib/components/docs/component-preview.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,10 @@
export let style = "";
</script>

<div
class={cn("group relative my-4 flex flex-col space-y-2", className)}
{...$$restProps}
>
<div class={cn("group relative my-4 flex flex-col space-y-2", className)} {...$$restProps}>
<Tabs.Root value="preview" class="relative mr-auto w-full">
<div class="flex items-center justify-between pb-3">
<Tabs.List
class="w-full justify-start rounded-none border-b bg-transparent p-0"
>
<Tabs.List class="w-full justify-start rounded-none border-b bg-transparent p-0">
<Tabs.Trigger
value="preview"
class="relative h-9 rounded-none border-b-2 border-b-transparent bg-transparent px-4 pb-3 pt-2 font-semibold text-muted-foreground shadow-none transition-none data-[state=active]:border-b-primary data-[state=active]:text-foreground data-[state=active]:shadow-none"
Expand Down Expand Up @@ -66,12 +61,8 @@
>
<slot name="example">
{#await component}
<div
class="flex items-center text-sm text-muted-foreground"
>
<Icons.spinner
class="mr-2 h-4 w-4 animate-spin"
/>
<div class="flex items-center text-sm text-muted-foreground">
<Icons.spinner class="mr-2 h-4 w-4 animate-spin" />
Loading...
</div>
{:then Component}
Expand Down
Loading

1 comment on commit d48d69f

@vercel
Copy link

@vercel vercel bot commented on d48d69f Jan 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.