Skip to content

Commit

Permalink
feat: add Alert component
Browse files Browse the repository at this point in the history
  • Loading branch information
bacali95 committed May 5, 2022
1 parent e12f19d commit e9d792b
Show file tree
Hide file tree
Showing 19 changed files with 416 additions and 48 deletions.
13 changes: 11 additions & 2 deletions apps/docs/src/app/app.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@
clip-rule="evenodd"
></path>
</svg>
<a class="text-xl font-semibold dark:text-white cursor-pointer" routerLink="">Flowbite Angular Components</a>
<a
class="cursor-pointer text-xl font-semibold dark:text-white"
routerLink=""
>Flowbite Angular Components</a
>
</div>
<div class="flex items-center gap-2">
<a
Expand Down Expand Up @@ -49,7 +53,12 @@
<div class="flex h-full overflow-hidden bg-gray-50 dark:bg-gray-900">
<flowbite-sidebar extraClass="border-r">
<flowbite-sidebar-item-group>
<flowbite-sidebar-item *ngFor="let route of routes" [icon]="route.icon" [link]="route.href">{{route.title}}</flowbite-sidebar-item>
<flowbite-sidebar-item
*ngFor="let component of components"
[icon]="component.icon"
[link]="component.href"
>{{ component.title }}</flowbite-sidebar-item
>
</flowbite-sidebar-item-group>
</flowbite-sidebar>
<main class="flex-1 overflow-auto p-4">
Expand Down
4 changes: 2 additions & 2 deletions apps/docs/src/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { Component } from '@angular/core';
import { SidebarService } from 'flowbite-angular';

import { routes } from './routing/routes';
import { components } from './common';

@Component({
selector: 'flowbite-root',
templateUrl: './app.component.html',
})
export class AppComponent {
routes = routes;
components = components;

constructor(public readonly sidebarService: SidebarService) {}
}
5 changes: 4 additions & 1 deletion apps/docs/src/app/app.module.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FlowbiteModule } from 'flowbite-angular';
import { ScullyLibModule } from '@scullyio/ng-lib';

import 'prismjs';
import 'prismjs/components/prism-xml-doc';
import 'prismjs/components/prism-typescript';

import { AppComponent } from './app.component';
import { RoutingModule } from './routing/routing.module';
import {
AlertPageComponent,
BadgePageComponent,
DashboardPageComponent,
SidebarPageComponent,
Expand All @@ -17,9 +20,9 @@ import {
DemoPageComponent,
PrismComponent,
} from './common';
import { ScullyLibModule } from '@scullyio/ng-lib';

const PAGES_COMPONENTS = [
AlertPageComponent,
BadgePageComponent,
DashboardPageComponent,
SidebarPageComponent,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,23 @@ export type RouteProps = {
card?: ComponentCardItem;
};

export const routes: RouteProps[] = [
export const components: RouteProps[] = [
{
title: 'Dashboard',
href: '',
group: false,
icon: `<svg stroke="currentColor" fill="currentColor" stroke-width="0" viewBox="0 0 20 20" class="h-6 w-6 text-gray-500 transition duration-75 group-hover:text-gray-900 dark:text-gray-400 dark:group-hover:text-white" height="1em" width="1em" xmlns="http://www.w3.org/2000/svg"><path d="M10.707 2.293a1 1 0 00-1.414 0l-7 7a1 1 0 001.414 1.414L4 10.414V17a1 1 0 001 1h2a1 1 0 001-1v-2a1 1 0 011-1h2a1 1 0 011 1v2a1 1 0 001 1h2a1 1 0 001-1v-6.586l.293.293a1 1 0 001.414-1.414l-7-7z"></path></svg>`,
},
{
title: 'Alerts',
icon: '<svg stroke="currentColor" fill="currentColor" stroke-width="0" viewBox="0 0 20 20" class="h-6 w-6 text-gray-500 transition duration-75 group-hover:text-gray-900 dark:text-gray-400 dark:group-hover:text-white" height="1em" width="1em" xmlns="http://www.w3.org/2000/svg"><path d="M10 2a6 6 0 00-6 6v3.586l-.707.707A1 1 0 004 14h12a1 1 0 00.707-1.707L16 11.586V8a6 6 0 00-6-6zM10 18a3 3 0 01-3-3h6a3 3 0 01-3 3z"></path></svg>',
href: '/alerts',
group: false,
card: {
className: 'w-56',
images: { light: 'alerts-light.svg', dark: 'alerts-dark.svg' },
},
},
{
title: 'Badges',
href: 'badges',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,17 @@ import { Component, Input } from '@angular/core';
>
<div class="flex h-full w-full flex-col justify-center gap-6 p-6">
<ng-content></ng-content>
<flowbite-prism [code]="code.trim()" language="xml"></flowbite-prism>
<flowbite-prism
*ngFor="let code of codes"
[code]="code.code.trim()"
[language]="code.language"
></flowbite-prism>
</div>
</div>
</div>`,
})
export class DemoExampleComponent {
@Input() title?: string;
@Input() code = '';
@Input() codes: { language: string; code: string }[] = [];
@Input() codeClassName?: string;
}
1 change: 1 addition & 0 deletions apps/docs/src/app/common/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './demo-example/demo-example.component';
export * from './demo-page/demo-page.component';
export * from './prism/prism.component';
export * from './components';
24 changes: 24 additions & 0 deletions apps/docs/src/app/pages/alert-page/alert-page.component.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';

import { AlertPageComponent } from './alert-page.component';

describe('AlertPageComponent', () => {
let component: AlertPageComponent;
let fixture: ComponentFixture<AlertPageComponent>;

beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [AlertPageComponent],
}).compileComponents();
});

beforeEach(() => {
fixture = TestBed.createComponent(AlertPageComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});
167 changes: 167 additions & 0 deletions apps/docs/src/app/pages/alert-page/alert-page.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
import { Component } from '@angular/core';

@Component({
selector: 'flowbite-alert-page',
template: `
<flowbite-demo-page>
<flowbite-demo-example title="Default Badge" [codes]="[examples[0]]">
<flowbite-alert>
<span class="font-medium">Info alert!</span> Change a few things up
and try submitting again.
</flowbite-alert>
</flowbite-demo-example>
<flowbite-demo-example title="Alerts with icon" [codes]="[examples[1]]">
<flowbite-alert [icon]="icon" color="red">
<span class="font-medium">Info alert!</span> Change a few things up
and try submitting again.
</flowbite-alert>
</flowbite-demo-example>
<flowbite-demo-example
title="Dismissible alerts"
[codes]="[examples[2], examples[3]]"
>
<flowbite-alert color="green" [dismiss]="onDismiss">
<span class="font-medium">Info alert!</span> Change a few things up
and try submitting again.
</flowbite-alert>
</flowbite-demo-example>
<flowbite-demo-example title="Border accent" [codes]="[examples[4]]">
<flowbite-alert
color="yellow"
[withBorderAccent]="true"
[rounded]="false"
>
<span class="font-medium">Info alert!</span> Change a few things up
and try submitting again.
</flowbite-alert>
</flowbite-demo-example>
<flowbite-demo-example title="Additional content" [codes]="[examples[5]]">
<flowbite-alert
color="gray"
[icon]="icon"
[additionalContent]="additionalContent"
>
<h3 class="text-lg font-medium text-gray-700 dark:text-gray-100">
This is an info alert
</h3>
</flowbite-alert>
</flowbite-demo-example>
<ng-template #icon>
<svg
stroke="currentColor"
fill="currentColor"
stroke-width="0"
viewBox="0 0 20 20"
class="mr-3 inline h-5 w-5 flex-shrink-0"
height="1em"
width="1em"
xmlns="http://www.w3.org/2000/svg"
>
<path
fill-rule="evenodd"
d="M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-7-4a1 1 0 11-2 0 1 1 0 012 0zM9 9a1 1 0 000 2v3a1 1 0 001 1h1a1 1 0 100-2v-3a1 1 0 00-1-1H9z"
clip-rule="evenodd"
></path>
</svg>
</ng-template>
<ng-template #additionalContent>
<div class="mt-2 mb-4 text-sm text-gray-700 dark:text-gray-100">
More info about this info alert goes here. This example text is going
to run a bit longer so that you can see how spacing within an alert
works with this kind of content.
</div>
<div class="flex">
<button
type="button"
class="mr-2 inline-flex items-center rounded-lg bg-gray-700 px-3 py-1.5 text-center text-xs font-medium text-gray-100 hover:bg-gray-800 focus:ring-4 focus:ring-gray-300 dark:bg-gray-100 dark:text-gray-700 dark:hover:bg-gray-200"
>
<svg
stroke="currentColor"
fill="currentColor"
stroke-width="0"
viewBox="0 0 20 20"
class="-ml-0.5 mr-2 h-4 w-4"
height="1em"
width="1em"
xmlns="http://www.w3.org/2000/svg"
>
<path d="M10 12a2 2 0 100-4 2 2 0 000 4z"></path>
<path
fill-rule="evenodd"
d="M.458 10C1.732 5.943 5.522 3 10 3s8.268 2.943 9.542 7c-1.274 4.057-5.064 7-9.542 7S1.732 14.057.458 10zM14 10a4 4 0 11-8 0 4 4 0 018 0z"
clip-rule="evenodd"
></path>
</svg>
View more
</button>
<button
type="button"
class="rounded-lg border border-gray-700 bg-transparent px-3 py-1.5 text-center text-xs font-medium text-gray-700 hover:bg-gray-800 hover:text-white focus:ring-4 focus:ring-gray-300 dark:border-gray-100 dark:text-gray-100 dark:hover:text-white"
>
Dismiss
</button>
</div>
</ng-template>
</flowbite-demo-page>
`,
})
export class AlertPageComponent {
examples = [
{
language: 'html',
code: `
<flowbite-alert>
<span class="font-medium">Info alert!</span> Change a few things up
and try submitting again.
</flowbite-alert>
`,
},
{
language: 'html',
code: `
<flowbite-alert [icon]="icon" color="red">
<span class="font-medium">Info alert!</span> Change a few things up
and try submitting again.
</flowbite-alert>
<ng-template #icon><svg>...</svg></ng-template>`,
},
{
language: 'ts',
code: `onDismiss = () => alert('Alert dismissed!');`,
},
{
language: 'html',
code: `
<flowbite-alert color="green" [dismiss]="onDismiss">
<span class="font-medium">Info alert!</span> Change a few things up
and try submitting again.
</flowbite-alert>`,
},
{
language: 'html',
code: `
<flowbite-alert
color="yellow"
[withBorderAccent]="true"
[rounded]="false"
>
<span class="font-medium">Info alert!</span> Change a few things up
and try submitting again.
</flowbite-alert>`,
},
{
language: 'html',
code: `
<flowbite-alert [icon]="icon" [additionalContent]="additionalContent">
<h3 class="text-lg font-medium text-blue-700 dark:text-blue-800">
This is an info alert
</h3>
</flowbite-alert>
<ng-template #icon><svg>...</svg></ng-template>
<ng-template #additionalContent><svg>...</svg></ng-template>
`,
},
];

onDismiss = () => alert('Alert dismissed!');
}
Loading

0 comments on commit e9d792b

Please sign in to comment.