Skip to content

Commit

Permalink
docs(registry): add aspect-ratio
Browse files Browse the repository at this point in the history
  • Loading branch information
adrian-ub committed Oct 25, 2024
1 parent 75c629e commit 40e4b9a
Show file tree
Hide file tree
Showing 9 changed files with 167 additions and 6 deletions.
2 changes: 1 addition & 1 deletion docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"@ng-icons/core": "^29.5.0",
"@ng-icons/lucide": "^29.5.0",
"@ng-icons/radix-icons": "^29.5.0",
"@radix-ng/primitives": "^0.13.0",
"@radix-ng/primitives": "^0.15.0",
"astro": "^4.16.6",
"class-variance-authority": "^0.7.0",
"clsx": "^2.1.1",
Expand Down
6 changes: 6 additions & 0 deletions docs/src/config/docs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,12 @@ export const docsConfig: TDocsConfig = {
href: '/docs/components/alert',
items: [],
},
{
title: 'Aspect Ratio',
href: '/docs/components/aspect-ratio',
items: [],
label: 'New',
},
{
title: 'Avatar',
href: '/docs/components/avatar',
Expand Down
63 changes: 63 additions & 0 deletions docs/src/content/docs/components/aspect-ratio.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
---
title: Aspect Ratio
description: Displays content within a desired ratio.
links:
doc: https://www.radix-ng.com/primitives/components/aspect-ratio
api: https://www.radix-ng.com/primitives/components/aspect-ratio#api-reference
---

<ComponentPreview
name="aspect-ratio-demo"
title="Aspect Ratio"
description="A component that displays an image with a 16:9 aspect ratio."
/>

## Installation

<Tabs defaultValue="cli">

<TabsList>
<TabsTrigger value="cli">CLI</TabsTrigger>
<TabsTrigger value="manual">Manual</TabsTrigger>
</TabsList>
<TabsContent value="cli">

```bash
npx shadcn-ng@latest add aspect-ratio
```

</TabsContent>

<TabsContent value="manual">

<Steps>

<Step>Install the following dependencies:</Step>

```bash
npm install @radix-ng/primitives
```

<Step>Copy and paste the following code into your project.</Step>

<ComponentSource name="aspect-ratio" />

<Step>Update the import paths to match your project setup.</Step>

</Steps>

</TabsContent>

</Tabs>

## Usage

```ts
import { UbAspectRatioDirective } from "@/components/ui/aspect-ratio"
```

```html
<div ubAspectRatio [ratio]="16 / 9">
<img src="..." alt="Image" class="rounded-md object-cover" >
</div>
```
28 changes: 28 additions & 0 deletions docs/src/registry/default/example/aspect-ratio-demo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { UbAspectRatioDirective } from '@/registry/default/ui/aspect-ratio'

import { NgOptimizedImage } from '@angular/common'
import { Component } from '@angular/core'

@Component({
standalone: true,
selector: 'aspect-ratio-demo-default',
imports: [UbAspectRatioDirective, NgOptimizedImage],
template: `
<div class="w-96">
<div ubAspectRatio [ratio]="16 / 9" class="bg-muted">
<img
ngSrc="https://images.unsplash.com/photo-1588345921523-c2dcdb7f1dcd?w=800&dpr=2&q=80"
alt="Photo by Drew Beamer"
fill
class="h-full w-full rounded-md object-cover"
ngSrcset="640w, 750w, 828w, 1080w, 1200w, 1920w, 2048w, 3840w"
sizes="100vw"
style="position: absolute; height: 100%; width: 100%; inset: 0px; color: transparent;"
/>
</div>
</div>
`,
})
export class AspectRatioDemoDefault { }

export default AspectRatioDemoDefault
15 changes: 15 additions & 0 deletions docs/src/registry/default/ui/aspect-ratio.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Directive } from '@angular/core'

import { RdxAspectRatioDirective } from '@radix-ng/primitives/aspect-ratio'

@Directive({
standalone: true,
selector: '[ubAspectRatio]',
hostDirectives: [
{
directive: RdxAspectRatioDirective,
inputs: ['ratio'],
},
],
})
export class UbAspectRatioDirective { }
28 changes: 28 additions & 0 deletions docs/src/registry/new-york/example/aspect-ratio-demo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { UbAspectRatioDirective } from '@/registry/new-york/ui/aspect-ratio'

import { NgOptimizedImage } from '@angular/common'
import { Component } from '@angular/core'

@Component({
standalone: true,
selector: 'aspect-ratio-demo-new-york',
imports: [UbAspectRatioDirective, NgOptimizedImage],
template: `
<div class="w-96">
<div ubAspectRatio [ratio]="16 / 9" class="bg-muted">
<img
ngSrc="https://images.unsplash.com/photo-1588345921523-c2dcdb7f1dcd?w=800&dpr=2&q=80"
alt="Photo by Drew Beamer"
fill
class="h-full w-full rounded-md object-cover"
ngSrcset="640w, 750w, 828w, 1080w, 1200w, 1920w, 2048w, 3840w"
sizes="100vw"
style="position: absolute; height: 100%; width: 100%; inset: 0px; color: transparent;"
/>
</div>
</div>
`,
})
export class AspectRatioDemoNewYork { }

export default AspectRatioDemoNewYork
15 changes: 15 additions & 0 deletions docs/src/registry/new-york/ui/aspect-ratio.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Directive } from '@angular/core'

import { RdxAspectRatioDirective } from '@radix-ng/primitives/aspect-ratio'

@Directive({
standalone: true,
selector: '[ubAspectRatio]',
hostDirectives: [
{
directive: RdxAspectRatioDirective,
inputs: ['ratio'],
},
],
})
export class UbAspectRatioDirective { }
6 changes: 6 additions & 0 deletions docs/src/registry/registry-ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ export const ui: Registry = [
type: 'registry:ui',
files: ['ui/alert.ts'],
},
{
name: 'aspect-ratio',
type: 'registry:ui',
dependencies: ['@radix-ng/primitives'],
files: ['ui/aspect-ratio.ts'],
},
{
name: 'avatar',
type: 'registry:ui',
Expand Down
10 changes: 5 additions & 5 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 40e4b9a

Please sign in to comment.