Skip to content

Commit 254583e

Browse files
author
MGREMY
committed
feat(docs): add size demo
1 parent 614f87a commit 254583e

File tree

7 files changed

+114
-49
lines changed

7 files changed

+114
-49
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { Directive, ElementRef, inject, Input } from '@angular/core';
2+
3+
@Directive({
4+
selector: 'iframe[flowbiteIframeChachedSrc]',
5+
standalone: true,
6+
})
7+
export class IframeCachedSrcDirective {
8+
protected elementRef = inject(ElementRef);
9+
10+
@Input()
11+
public get cachedSrc(): string {
12+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
13+
return this.elementRef.nativeElement.src;
14+
}
15+
public set cachedSrc(value: string) {
16+
if (this.elementRef.nativeElement.src !== value) {
17+
this.elementRef.nativeElement.src = value;
18+
}
19+
}
20+
}

apps/docs/src/app/frames/iframe-wrapper.component.ts

Lines changed: 43 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,34 @@
11
import { FlowbiteIFrameComponent } from './iframe.component';
22

3-
import type { ThemeState } from 'flowbite-angular';
3+
import type { FlowbiteTheme, ThemeState } from 'flowbite-angular';
44
import { ButtonComponent, GlobalSignalStoreService } from 'flowbite-angular';
55

6+
import { NgClass } from '@angular/common';
67
import type { AfterViewInit } from '@angular/core';
7-
import { afterNextRender, Component, effect, inject, Injector, input, numberAttribute, ViewChild } from '@angular/core';
8+
import {
9+
afterNextRender,
10+
Component,
11+
effect,
12+
inject,
13+
Injector,
14+
input,
15+
numberAttribute,
16+
signal,
17+
untracked,
18+
ViewChild,
19+
} from '@angular/core';
820

921
@Component({
1022
selector: 'flowbite-iframe-wrapper',
1123
standalone: true,
12-
imports: [FlowbiteIFrameComponent, ButtonComponent],
24+
imports: [FlowbiteIFrameComponent, ButtonComponent, NgClass],
1325
template: `
14-
<div class="flex flex-col grow">
26+
<div
27+
class="flex flex-col grow rounded-t-xl"
28+
[ngClass]="{
29+
'bg-white': contentThemeMode() === 'light',
30+
'bg-gray-900': contentThemeMode() === 'dark',
31+
}">
1532
<div
1633
class="flex flex-row justify-between items-center rounded-t-xl p-6 border-b bg-gray-50 border-b-gray-200 dark:bg-gray-800 dark:border-b-gray-700 dark:text-gray-400">
1734
<span>
@@ -56,11 +73,12 @@ import { afterNextRender, Component, effect, inject, Injector, input, numberAttr
5673
Show on Github
5774
</flowbite-button>
5875
</span>
59-
<span class="flex flex-row gap-2">
76+
<span class="hidden gap-2 lg:flex lg:flex-row">
6077
<flowbite-button
6178
color="light"
6279
size="sm"
63-
isPill>
80+
isPill
81+
(click)="iframe.width.set('lg')">
6482
<svg
6583
width="16"
6684
height="16"
@@ -78,7 +96,8 @@ import { afterNextRender, Component, effect, inject, Injector, input, numberAttr
7896
<flowbite-button
7997
color="light"
8098
size="sm"
81-
isPill>
99+
isPill
100+
(click)="iframe.width.set('md')">
82101
<svg
83102
width="16"
84103
height="16"
@@ -96,7 +115,8 @@ import { afterNextRender, Component, effect, inject, Injector, input, numberAttr
96115
<flowbite-button
97116
color="light"
98117
size="sm"
99-
isPill>
118+
isPill
119+
(click)="iframe.width.set('sm')">
100120
<svg
101121
width="16"
102122
height="16"
@@ -117,7 +137,7 @@ import { afterNextRender, Component, effect, inject, Injector, input, numberAttr
117137
color="light"
118138
size="sm"
119139
isPill
120-
(click)="iframe.setTheme('light')">
140+
(click)="setContentThemeMode('light')">
121141
<svg
122142
stroke="currentColor"
123143
fill="currentColor"
@@ -137,7 +157,7 @@ import { afterNextRender, Component, effect, inject, Injector, input, numberAttr
137157
color="light"
138158
size="sm"
139159
isPill
140-
(click)="iframe.setTheme('dark')">
160+
(click)="setContentThemeMode('dark')">
141161
<svg
142162
stroke="currentColor"
143163
fill="currentColor"
@@ -156,6 +176,7 @@ import { afterNextRender, Component, effect, inject, Injector, input, numberAttr
156176
[link]="link()"
157177
[height]="height()"
158178
[onLoadAction]="onIframeLoaded"
179+
width="lg"
159180
#iframe />
160181
</div>
161182
`,
@@ -169,6 +190,8 @@ export class FlowbiteIFrameWrapperComponent implements AfterViewInit {
169190
GlobalSignalStoreService<ThemeState>,
170191
);
171192

193+
protected contentThemeMode = signal<FlowbiteTheme | undefined>(undefined);
194+
172195
public link = input.required<string>();
173196
public githubLink = input<string>();
174197
public height = input<number, unknown>(150, { transform: numberAttribute });
@@ -178,18 +201,25 @@ export class FlowbiteIFrameWrapperComponent implements AfterViewInit {
178201
() => {
179202
effect(
180203
() => {
204+
this.contentThemeMode.set(this.themeStateService.select('theme')());
205+
181206
this.onIframeLoaded();
182207
},
183-
{ injector: this.injector },
208+
{ injector: this.injector, allowSignalWrites: true },
184209
);
185210
},
186211
{ injector: this.injector },
187212
);
188213
}
189214

190215
protected onIframeLoaded = () => {
191-
const theme = this.themeStateService.select('theme')();
216+
const theme = untracked(() => this.contentThemeMode());
192217

193-
this.iframe.setTheme(theme);
218+
this.setContentThemeMode(theme || this.themeStateService.select('theme')());
194219
};
220+
221+
protected setContentThemeMode(mode: FlowbiteTheme): void {
222+
this.iframe.setTheme(mode);
223+
this.contentThemeMode.set(mode);
224+
}
195225
}

apps/docs/src/app/frames/iframe.component.ts

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,40 @@
1+
import { IframeCachedSrcDirective } from './iframe-cached-src.directive';
2+
13
import type { FlowbiteTheme } from 'flowbite-angular';
24

3-
import type { AfterViewInit } from '@angular/core';
4-
import { ChangeDetectorRef, Component, ElementRef, inject, input, numberAttribute, ViewChild } from '@angular/core';
5+
import { NgClass } from '@angular/common';
6+
import {
7+
ChangeDetectorRef,
8+
Component,
9+
ElementRef,
10+
inject,
11+
input,
12+
model,
13+
numberAttribute,
14+
ViewChild,
15+
} from '@angular/core';
516
import { DomSanitizer } from '@angular/platform-browser';
617

718
@Component({
819
selector: 'flowbite-iframe',
920
standalone: true,
10-
imports: [],
21+
imports: [NgClass, IframeCachedSrcDirective],
1122
template: `
1223
<iframe
13-
[src]="sanitizer.bypassSecurityTrustResourceUrl(link())"
14-
class="w-full h-0 mx-auto bg-white iframe-code"
24+
flowbiteIframeChachedSrc
25+
[cachedSrc]="link()"
26+
class="w-full mx-auto iframe-code"
27+
[ngClass]="{
28+
'max-w-md': width() == 'md',
29+
'max-w-sm': width() === 'sm',
30+
}"
1531
frameborder="0"
16-
style="height: {{ height() }}px"
32+
loading="lazy"
1733
(load)="callOnLoadAction()"
1834
#iframe></iframe>
1935
`,
2036
})
21-
export class FlowbiteIFrameComponent implements AfterViewInit {
37+
export class FlowbiteIFrameComponent {
2238
@ViewChild('iframe', { static: false })
2339
// eslint-disable-next-line @typescript-eslint/no-explicit-any
2440
protected iframe!: ElementRef<any>;
@@ -27,13 +43,10 @@ export class FlowbiteIFrameComponent implements AfterViewInit {
2743
protected readonly changeDetectorRef = inject(ChangeDetectorRef);
2844

2945
public link = input.required<string>();
30-
public height = input<number, unknown>(150, { transform: numberAttribute });
46+
public height = input.required<number, unknown>({ transform: numberAttribute });
47+
public width = model.required<'sm' | 'md' | 'lg'>();
3148
public onLoadAction = input<() => void>();
3249

33-
public ngAfterViewInit(): void {
34-
this.changeDetectorRef.detach();
35-
}
36-
3750
public setTheme(theme: FlowbiteTheme): void {
3851
if (theme === 'light') this.iframe.nativeElement.contentDocument.documentElement.classList.remove('dark');
3952
else this.iframe.nativeElement.contentDocument.documentElement.classList.add('dark');

apps/docs/src/app/ui/features/docs/docs.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<div class="flex flex-row p-4 2xl:mx-60 2xl:my-8 gap-4">
1+
<div class="flex flex-row p-4 2xl:mx-60 gap-4">
22
<flowbite-sidebar>
33
<flowbite-sidebar-item-group title="GETTING STARTED">
44
<flowbite-sidebar-item [link]="['/ui', '/docs', '/getting-started', '/introduction']">
Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,25 @@
1-
<flowbite-navbar
2-
isFixed
3-
[customStyle]="{ base: 'flex flex-wrap items-center justify-between p-4 2xl:px-60' }">
4-
<flowbite-navbar-brand link="/">
5-
<img
6-
src="./assets/flowbite-angular-logo.svg"
7-
class="h-8"
8-
alt="Flowbite Logo" />
9-
<span class="self-center text-2xl font-semibold whitespace-nowrap dark:text-white">Flowbite Angular</span>
10-
</flowbite-navbar-brand>
11-
<flowbite-navbar-content>
12-
<flowbite-navbar-item link="/ui/docs">Docs</flowbite-navbar-item>
13-
<flowbite-navbar-item link="https://flowbite.com">Flowbite</flowbite-navbar-item>
14-
</flowbite-navbar-content>
15-
<div class="flex flex-row">
16-
<flowbite-dark-theme-toggle />
17-
<flowbite-navbar-toggle />
18-
</div>
19-
</flowbite-navbar>
1+
<section class="antialiased dark:bg-gray-900">
2+
<flowbite-navbar
3+
isFixed
4+
[customStyle]="{ base: 'flex flex-wrap items-center justify-between p-4 2xl:px-60' }">
5+
<flowbite-navbar-brand link="/">
6+
<img
7+
src="./assets/flowbite-angular-logo.svg"
8+
class="h-8"
9+
alt="Flowbite Logo" />
10+
<span class="self-center text-2xl font-semibold whitespace-nowrap dark:text-white">Flowbite Angular</span>
11+
</flowbite-navbar-brand>
12+
<flowbite-navbar-content>
13+
<flowbite-navbar-item link="/ui/docs">Docs</flowbite-navbar-item>
14+
<flowbite-navbar-item link="https://flowbite.com">Flowbite</flowbite-navbar-item>
15+
</flowbite-navbar-content>
16+
<div class="flex flex-row">
17+
<flowbite-dark-theme-toggle />
18+
<flowbite-navbar-toggle />
19+
</div>
20+
</flowbite-navbar>
2021

21-
<router-outlet />
22+
<router-outlet />
2223

23-
<flowbite-scroll-top />
24+
<flowbite-scroll-top />
25+
</section>

apps/docs/src/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
sizes="32x32"
1313
href="./assets/flowbite-angular-logo.svg" />
1414
</head>
15-
<body class="antialiased dark:bg-gray-900">
15+
<body>
1616
<flowbite-root></flowbite-root>
1717
</body>
1818
</html>

apps/docs/tailwind.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const sharedTailwindConfig = require('../../libs/flowbite-angular/tailwind.confi
1111
module.exports = {
1212
presets: [sharedTailwindConfig],
1313
content: [join(__dirname, 'src/**/!(*.stories|*.spec).{ts,html}'), ...createGlobPatternsForDependencies(__dirname)],
14-
safelist: ['p-4', 'overflow-x-auto', 'rounded-md'],
14+
safelist: ['p-4', 'overflow-x-auto', 'rounded-md', 'max-w-md', 'max-w-sm', 'bg-gray-100', 'bg-gray-500'],
1515
theme: {
1616
extend: {
1717
colors: {

0 commit comments

Comments
 (0)