Skip to content

Commit

Permalink
feat: add tabs component
Browse files Browse the repository at this point in the history
  • Loading branch information
adrian-ub committed Jul 23, 2024
1 parent 51997f8 commit 74977a8
Show file tree
Hide file tree
Showing 6 changed files with 286 additions and 7 deletions.
10 changes: 7 additions & 3 deletions apps/www/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"@analogjs/astro-angular": "^1.6.3",
"@angular-devkit/build-angular": "^18.1.1",
"@angular/animations": "^18.1.1",
"@angular/cdk": "^18.1.1",
"@angular/common": "^18.1.1",
"@angular/compiler": "^18.1.1",
"@angular/compiler-cli": "^18.1.1",
Expand All @@ -26,17 +27,20 @@
"@astrojs/starlight": "^0.25.2",
"@astrojs/starlight-tailwind": "^2.0.3",
"@astrojs/tailwind": "^5.1.0",
"@radix-ng/primitives": "^0.8.2",
"astro": "^4.12.2",
"class-variance-authority": "^0.7.0",
"clsx": "^2.1.1",
"lodash.template": "^4.5.0",
"rxjs": "^7.8.1",
"sharp": "^0.32.5",
"tailwind-merge": "^2.4.0",
"tailwindcss": "^3.4.4",
"tslib": "^2.6.3",
"typescript": "^5.5.3",
"zone.js": "^0.14.8",
"@types/lodash.template": "^4.5.1",
"lodash.template": "^4.5.0"
"zone.js": "^0.14.8"
},
"devDependencies": {
"@types/lodash.template": "^4.5.1"
}
}
86 changes: 86 additions & 0 deletions apps/www/src/registry/default/ui/tabs.directive.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import { computed, Directive, Input, input } from "@angular/core";

import {
RdxTabsContentDirective,
RdxTabsListDirective,
RdxTabsRootDirective,
RdxTabsTriggerDirective,
} from "@radix-ng/primitives/tabs";

import { cn } from "@/lib/utils";

@Directive({
selector: "[ubTabs]",
standalone: true,
hostDirectives: [
{
directive: RdxTabsRootDirective,
inputs: ["defaultValue: ubDefaultValue"],
},
],
})
export class UbTabsDirective {
@Input() ubDefaultValue?: string;
}

@Directive({
selector: "[ubTabsList]",
standalone: true,
hostDirectives: [RdxTabsListDirective],
host: {
"[class]": "computedClass()",
},
})
export class UbTabsListDirective {
readonly class = input<string>();
protected computedClass = computed(() =>
cn(
"inline-flex h-10 items-center justify-center rounded-md bg-muted p-1 text-muted-foreground",
this.class()
)
);
}

@Directive({
selector: "[ubTabsTrigger]",
standalone: true,
hostDirectives: [
{ directive: RdxTabsTriggerDirective, inputs: ["value: value"] },
],
host: {
"[class]": "computedClass()",
},
})
export class UbTabsTriggerDirective {
readonly value = input.required<string>();

readonly class = input<string>();
protected computedClass = computed(() =>
cn(
"inline-flex items-center justify-center whitespace-nowrap rounded-sm px-3 py-1.5 text-sm font-medium ring-offset-background transition-all focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 data-[state=active]:bg-background data-[state=active]:text-foreground data-[state=active]:shadow-sm",
this.class()
)
);
}

@Directive({
selector: "[ubTabsContent]",
standalone: true,
hostDirectives: [
{ directive: RdxTabsContentDirective, inputs: ["value: value"] },
],
host: {
"[class]": "computedClass()",
},
})
export class UbTabsContentDirective {
readonly value = input.required<string>();

readonly class = input<string>();
protected computedClass = computed(() =>
cn(
"mt-2 ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",
this.class()
)
);
}
86 changes: 86 additions & 0 deletions apps/www/src/registry/new-york/ui/tabs.directive.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import { computed, Directive, Input, input } from "@angular/core";

import {
RdxTabsContentDirective,
RdxTabsListDirective,
RdxTabsRootDirective,
RdxTabsTriggerDirective,
} from "@radix-ng/primitives/tabs";

import { cn } from "@/lib/utils";

@Directive({
selector: "[ubTabs]",
standalone: true,
hostDirectives: [
{
directive: RdxTabsRootDirective,
inputs: ["defaultValue: ubDefaultValue"],
},
],
})
export class UbTabsDirective {
@Input() ubDefaultValue?: string;
}

@Directive({
selector: "[ubTabsList]",
standalone: true,
hostDirectives: [RdxTabsListDirective],
host: {
"[class]": "computedClass()",
},
})
export class UbTabsListDirective {
readonly class = input<string>();
protected computedClass = computed(() =>
cn(
"inline-flex h-9 items-center justify-center rounded-lg bg-muted p-1 text-muted-foreground",
this.class()
)
);
}

@Directive({
selector: "[ubTabsTrigger]",
standalone: true,
hostDirectives: [
{ directive: RdxTabsTriggerDirective, inputs: ["value: value"] },
],
host: {
"[class]": "computedClass()",
},
})
export class UbTabsTriggerDirective {
readonly value = input.required<string>();

readonly class = input<string>();
protected computedClass = computed(() =>
cn(
"inline-flex items-center justify-center whitespace-nowrap rounded-md px-3 py-1 text-sm font-medium ring-offset-background transition-all focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 data-[state=active]:bg-background data-[state=active]:text-foreground data-[state=active]:shadow",
this.class()
)
);
}

@Directive({
selector: "[ubTabsContent]",
standalone: true,
hostDirectives: [
{ directive: RdxTabsContentDirective, inputs: ["value: value"] },
],
host: {
"[class]": "computedClass()",
},
})
export class UbTabsContentDirective {
readonly value = input.required<string>();

readonly class = input<string>();
protected computedClass = computed(() =>
cn(
"mt-2 ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",
this.class()
)
);
}
6 changes: 6 additions & 0 deletions apps/www/src/registry/ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,10 @@ export const ui: Registry = [
type: "components:ui",
files: ["ui/skeleton.directive.ts"],
},
{
name: "tabs",
type: "components:ui",
dependencies: ["@angular/cdk", "@radix-ng/primitives"],
files: ["ui/tabs.directive.ts"],
},
];
64 changes: 63 additions & 1 deletion apps/www/tailwind.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,74 @@ import starlightPlugin from "@astrojs/starlight-tailwind";

/** @type {import('tailwindcss').Config} */
export default {
content: ["./src/**/*.{astro,html,js,jsx,md,mdx,svelte,ts,tsx,vue}"],
darkMode: "class",
content: [
"./src/**/*.{astro,html,js,jsx,md,mdx,svelte,ts,tsx,vue,directive.ts}",
],
theme: {
container: {
center: true,
padding: "2rem",
screens: {
"2xl": "1400px",
},
},
extend: {
colors: {
accent: colors.neutral,
gray: colors.neutral,
border: "hsl(var(--border))",
input: "hsl(var(--input))",
ring: "hsl(var(--ring))",
background: "hsl(var(--background))",
foreground: "hsl(var(--foreground))",
primary: {
DEFAULT: "hsl(var(--primary))",
foreground: "hsl(var(--primary-foreground))",
},
secondary: {
DEFAULT: "hsl(var(--secondary))",
foreground: "hsl(var(--secondary-foreground))",
},
destructive: {
DEFAULT: "hsl(var(--destructive))",
foreground: "hsl(var(--destructive-foreground))",
},
muted: {
DEFAULT: "hsl(var(--muted))",
foreground: "hsl(var(--muted-foreground))",
},
accent: {
DEFAULT: "hsl(var(--accent))",
foreground: "hsl(var(--accent-foreground))",
},
popover: {
DEFAULT: "hsl(var(--popover))",
foreground: "hsl(var(--popover-foreground))",
},
card: {
DEFAULT: "hsl(var(--card))",
foreground: "hsl(var(--card-foreground))",
},
},
borderRadius: {
lg: "var(--radius)",
md: "calc(var(--radius) - 2px)",
sm: "calc(var(--radius) - 4px)",
},
keyframes: {
"accordion-down": {
from: { height: "0" },
to: { height: "var(--radix-accordion-content-height)" },
},
"accordion-up": {
from: { height: "var(--radix-accordion-content-height)" },
to: { height: "0" },
},
},
animation: {
"accordion-down": "accordion-down 0.2s ease-out",
"accordion-up": "accordion-up 0.2s ease-out",
},
},
},
Expand Down
41 changes: 38 additions & 3 deletions pnpm-lock.yaml

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

0 comments on commit 74977a8

Please sign in to comment.