From c03563cedfd23f4c0108332cae5e3d44c1159eed Mon Sep 17 00:00:00 2001 From: Tyler Senter Date: Wed, 11 Dec 2024 09:32:19 -0500 Subject: [PATCH] docs: Add pages for modifiers (#306) * chore: Add docs page for `on-destroy` * chore: Add docs page for `on-insert` * chore: Add docs page for `on-click-outside` * chore: Add docs page for `on-update` --- .../f/modifiers/on-click-outside.gts | 25 ++++++ .../app/components/f/modifiers/on-destroy.gts | 79 +++++++++++++++++++ .../app/components/f/modifiers/on-insert.gts | 71 +++++++++++++++++ .../app/components/f/modifiers/on-update.gts | 24 ++++++ apps/docs-app/app/router.ts | 7 +- apps/docs-app/app/styles/app.css | 11 +++ apps/docs-app/app/templates/modifiers.hbs | 17 +++- .../templates/modifiers/on-click-outside.hbs | 5 ++ .../app/templates/modifiers/on-destroy.hbs | 5 ++ .../app/templates/modifiers/on-insert.hbs | 5 ++ .../app/templates/modifiers/on-update.hbs | 5 ++ 11 files changed, 252 insertions(+), 2 deletions(-) create mode 100644 apps/docs-app/app/components/f/modifiers/on-click-outside.gts create mode 100644 apps/docs-app/app/components/f/modifiers/on-destroy.gts create mode 100644 apps/docs-app/app/components/f/modifiers/on-insert.gts create mode 100644 apps/docs-app/app/components/f/modifiers/on-update.gts create mode 100644 apps/docs-app/app/templates/modifiers/on-click-outside.hbs create mode 100644 apps/docs-app/app/templates/modifiers/on-destroy.hbs create mode 100644 apps/docs-app/app/templates/modifiers/on-insert.hbs create mode 100644 apps/docs-app/app/templates/modifiers/on-update.hbs diff --git a/apps/docs-app/app/components/f/modifiers/on-click-outside.gts b/apps/docs-app/app/components/f/modifiers/on-click-outside.gts new file mode 100644 index 000000000..ebcefd483 --- /dev/null +++ b/apps/docs-app/app/components/f/modifiers/on-click-outside.gts @@ -0,0 +1,25 @@ +import { action } from '@ember/object'; +import { service } from '@ember/service'; +import Component from '@glimmer/component'; +import { Toaster, onClickOutside } from '@nrg-ui/core'; + +export default class OnInsertComponent extends Component { + @service + toast; + + @action + clickOutside(evt: PointerEvent) { + this.toast.info('Item clicked outside'); + console.log('Clicked outside:', evt); + } + + +} diff --git a/apps/docs-app/app/components/f/modifiers/on-destroy.gts b/apps/docs-app/app/components/f/modifiers/on-destroy.gts new file mode 100644 index 000000000..9c7f1076b --- /dev/null +++ b/apps/docs-app/app/components/f/modifiers/on-destroy.gts @@ -0,0 +1,79 @@ +import { fn } from '@ember/helper'; +import { on } from '@ember/modifier'; +import { service } from '@ember/service'; +import Component from '@glimmer/component'; +import { tracked } from '@glimmer/tracking'; +import { Button, TextInput, Toaster, bind, onDestroy } from '@nrg-ui/core'; +import { TrackedArray } from 'tracked-built-ins'; + +import type { TOC } from '@glint/template'; + +interface ItemSignature { + Args: { + label?: string; + + onDestroy: () => void; + onRemove: () => void; + }; +} + +const Item: TOC = ; + +export default class OnDestroyComponent extends Component { + @service + toast; + + @tracked + newItem; + + items: string[] = new TrackedArray([ + 'Item 1', + 'Item 2', + 'Item 3', + 'Item 4', + 'Item 5', + 'Item 6', + 'Item 7', + ]); + + add = () => { + this.items.push(this.newItem); + + this.newItem = ''; + }; + + remove = (index: number) => { + this.items.splice(index, 1); + }; + + destroy = (item: string) => { + this.toast.info(`Item "${item}" has been destroyed`); + console.log(`Item "${item}" has been destroyed`); + }; + + +} diff --git a/apps/docs-app/app/components/f/modifiers/on-insert.gts b/apps/docs-app/app/components/f/modifiers/on-insert.gts new file mode 100644 index 000000000..5c25cde71 --- /dev/null +++ b/apps/docs-app/app/components/f/modifiers/on-insert.gts @@ -0,0 +1,71 @@ +import { fn } from '@ember/helper'; +import { on } from '@ember/modifier'; +import { service } from '@ember/service'; +import Component from '@glimmer/component'; +import { tracked } from '@glimmer/tracking'; +import { Button, TextInput, Toaster, bind, onInsert } from '@nrg-ui/core'; +import { TrackedArray } from 'tracked-built-ins'; + +import type { TOC } from '@glint/template'; + +interface ItemSignature { + Args: { + label?: string; + + onInsert: () => void; + onRemove: () => void; + }; +} + +const Item: TOC = ; + +export default class OnInsertComponent extends Component { + @service + toast; + + @tracked + newItem; + + items: string[] = new TrackedArray(); + + add = () => { + this.items.push(this.newItem); + + this.newItem = ''; + }; + + remove = (index: number) => { + this.items.splice(index, 1); + }; + + insert = (item: string, element: HTMLElement) => { + this.toast.info(`Item "${item}" has been inserted`); + console.log(`Item "${item}":`, element); + }; + + +} diff --git a/apps/docs-app/app/components/f/modifiers/on-update.gts b/apps/docs-app/app/components/f/modifiers/on-update.gts new file mode 100644 index 000000000..5b6a69039 --- /dev/null +++ b/apps/docs-app/app/components/f/modifiers/on-update.gts @@ -0,0 +1,24 @@ +import { service } from '@ember/service'; +import Component from '@glimmer/component'; +import { tracked } from '@glimmer/tracking'; +import { TextInput, Toaster, bind, onUpdate } from '@nrg-ui/core'; + +export default class OnDestroyComponent extends Component { + @service + toast; + + @tracked + value = 'Edit me!'; + + update = (element: HTMLElement, item: string) => { + this.toast.info(`Value updated to "${item}"`); + console.log(`value: "${item}"`, element); + }; + + +} diff --git a/apps/docs-app/app/router.ts b/apps/docs-app/app/router.ts index b332ca3f9..66ebe5f06 100644 --- a/apps/docs-app/app/router.ts +++ b/apps/docs-app/app/router.ts @@ -46,6 +46,11 @@ Router.map(function () { this.route('section-header'); this.route('service-pricing'); }); - this.route('modifiers'); + this.route('modifiers', function() { + this.route('on-click-outside'); + this.route('on-destroy'); + this.route('on-insert'); + this.route('on-update'); + }); this.route('services'); }); diff --git a/apps/docs-app/app/styles/app.css b/apps/docs-app/app/styles/app.css index 319d22c89..a2a1d163c 100644 --- a/apps/docs-app/app/styles/app.css +++ b/apps/docs-app/app/styles/app.css @@ -1,2 +1,13 @@ @import url("marketing-theme.css"); @import url("freestyle.css"); + +.grid-collection { + & .item { + border: 2px solid var(--bs-primary); + border-radius: var(--bs-border-radius); + + &:hover { + background-color: var(--bs-primary-bg-subtle); + } + } +} diff --git a/apps/docs-app/app/templates/modifiers.hbs b/apps/docs-app/app/templates/modifiers.hbs index cfdf91c7e..16ac5e238 100644 --- a/apps/docs-app/app/templates/modifiers.hbs +++ b/apps/docs-app/app/templates/modifiers.hbs @@ -1,2 +1,17 @@ {{page-title "Modifiers"}} -{{outlet}} \ No newline at end of file + +
+ + + <:group as |Item|> + + + + + + + +
+ {{outlet}} +
+
\ No newline at end of file diff --git a/apps/docs-app/app/templates/modifiers/on-click-outside.hbs b/apps/docs-app/app/templates/modifiers/on-click-outside.hbs new file mode 100644 index 000000000..8b8ee0d08 --- /dev/null +++ b/apps/docs-app/app/templates/modifiers/on-click-outside.hbs @@ -0,0 +1,5 @@ +{{page-title "on-click-outside"}} + +
+ +
\ No newline at end of file diff --git a/apps/docs-app/app/templates/modifiers/on-destroy.hbs b/apps/docs-app/app/templates/modifiers/on-destroy.hbs new file mode 100644 index 000000000..2aae1f2bd --- /dev/null +++ b/apps/docs-app/app/templates/modifiers/on-destroy.hbs @@ -0,0 +1,5 @@ +{{page-title "on-destroy"}} + +
+ +
\ No newline at end of file diff --git a/apps/docs-app/app/templates/modifiers/on-insert.hbs b/apps/docs-app/app/templates/modifiers/on-insert.hbs new file mode 100644 index 000000000..2b046b13f --- /dev/null +++ b/apps/docs-app/app/templates/modifiers/on-insert.hbs @@ -0,0 +1,5 @@ +{{page-title "on-insert"}} + +
+ +
\ No newline at end of file diff --git a/apps/docs-app/app/templates/modifiers/on-update.hbs b/apps/docs-app/app/templates/modifiers/on-update.hbs new file mode 100644 index 000000000..c8613a42e --- /dev/null +++ b/apps/docs-app/app/templates/modifiers/on-update.hbs @@ -0,0 +1,5 @@ +{{page-title "on-update"}} + +
+ +
\ No newline at end of file