Skip to content

Commit

Permalink
feat: dark mode samples
Browse files Browse the repository at this point in the history
  • Loading branch information
quentinderoubaix committed Feb 15, 2024
1 parent 0d8b725 commit 1710af4
Show file tree
Hide file tree
Showing 15 changed files with 90 additions and 10 deletions.
13 changes: 12 additions & 1 deletion angular/demo/src/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type {OnInit} from '@angular/core';
import {Component} from '@angular/core';
import {RouterModule} from '@angular/router';

Expand All @@ -11,4 +12,14 @@ import {RouterModule} from '@angular/router';
</div>
`,
})
export class AppComponent {}
export class AppComponent implements OnInit {
ngOnInit() {
window.addEventListener('storage', (event) => {
if (event.key === 'theme') {
if (event.newValue) {
document.documentElement.setAttribute('data-bs-theme', event.newValue);
}
}
});
}
}
2 changes: 1 addition & 1 deletion angular/demo/src/app/samples/rating/form.route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {FormControl, ReactiveFormsModule, Validators} from '@angular/forms';
<div class="text-success">Thanks!</div>
}
@if (ctrl.invalid) {
<div class="text-danger">Please rate us</div>
<div class="text-danger-emphasis">Please rate us</div>
}
</div>
<pre>Model: <span id="form-model"><b>{{ ctrl.value }}</b></span></pre>
Expand Down
6 changes: 6 additions & 0 deletions angular/demo/src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Demo</title>
<link rel="icon" type="image/svg+xml" href="agnosui-logo.svg" />
<script>
const theme = window.localStorage.getItem('theme');
if (theme === 'dark' || ((theme === 'auto' || !theme) && (window.parent ?? window).matchMedia('(prefers-color-scheme: dark)').matches)) {
document.documentElement.setAttribute('data-bs-theme', 'dark');
}
</script>
</head>
<body>
<div id="root">
Expand Down
15 changes: 15 additions & 0 deletions common/demo.scss
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,18 @@ main {
height: 30px;
}
}

[data-bs-theme='dark'] {
.btn-outline-primary {
--bs-btn-color: #3f8bfd;
}
.btn-outline-secondary {
--bs-btn-color: #848d94;
}
.btn-outline-danger {
--bs-btn-color: #e36370;
}
.btn-outline-success {
--bs-btn-color: #1d9f63;
}
}
6 changes: 3 additions & 3 deletions common/samples/progressbar/custom.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
padding: 0;
height: 210px;
width: 190px;
border: 10px solid #030303;
border: 10px solid var(--bs-body-color);
position: absolute;
transform: translate(-50%, -50%);
top: 50%;
Expand Down Expand Up @@ -42,7 +42,7 @@
position: absolute;
height: 80px;
width: 60px;
border: 10px solid #030303;
border: 10px solid var(--bs-body-color);
border-left: none;
right: -70px;
top: 30px;
Expand All @@ -53,7 +53,7 @@
content: '';
height: 10px;
width: 260px;
background-color: #030303;
background-color: var(--bs-body-color);
left: -45px;
bottom: -10px;
border-radius: 10px;
Expand Down
2 changes: 1 addition & 1 deletion demo/src/lib/layout/Sample.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
</script>

<div class="mb-4 py-2 px-0 px-sm-3">
<div class={`position-relative ${isDoc ? 'border-bottom' : 'border'} `}>
<div class={`position-relative ${isDoc ? 'border-bottom' : 'border'} iframe-container`}>
{#if $showSpinner$}
<div class="position-absolute top-50 start-50 translate-middle iframeSpinner">
<div class="spinner-border text-primary-emphasis" role="status">
Expand Down
9 changes: 8 additions & 1 deletion demo/src/lib/layout/iframe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export function createIframeHandler(defaultHeight: number, resize = true, messag
const onLoad = (event: Event) => {
if (event.target instanceof HTMLIFrameElement) {
setupObserver(event.target);
event.target.classList.add('loaded');
}
};

Expand All @@ -58,7 +59,12 @@ export function createIframeHandler(defaultHeight: number, resize = true, messag
}

const update = (baseSrc: string) => {
if (!iframe.contentWindow?.location?.href?.startsWith(baseSrc)) {
if (
!iframe.contentWindow?.location?.href?.startsWith(baseSrc) ||
!iframe.contentDocument ||
iframe.contentDocument.readyState === 'loading'
) {
iframe.classList.remove('loaded');
_iframeLoaded$.set(false);
if (spinnerTimer) {
clearTimeout(spinnerTimer);
Expand All @@ -79,6 +85,7 @@ export function createIframeHandler(defaultHeight: number, resize = true, messag
}
_iframeLoaded$.set(true);
_showSpinner$.set(false);
iframe.classList.add('loaded');
}
};
window.addEventListener('message', sampleLoad, false);
Expand Down
11 changes: 11 additions & 0 deletions demo/src/routes/styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -204,11 +204,22 @@ header {
}
}

iframe {
opacity: 0;
&.loaded {
opacity: 1;
}
}

// Dark mode override
@if $enable-dark-mode {
@include color-mode(dark, true) {
color-scheme: dark;

.iframe-container {
background-color: #212529;
}

@each $color, $value in $theme-colors-dark-rgb {
--#{$prefix}#{$color}-rgb: #{$value};
}
Expand Down
2 changes: 1 addition & 1 deletion e2e/samplesMarkup.e2e-spec.ts-snapshots/rating-form.html
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@
id="form-msg"
>
<div
class="text-danger"
class="text-danger-emphasis"
>
"Please rate us"
</div>
Expand Down
2 changes: 1 addition & 1 deletion react/demo/src/app/samples/rating/Form.route.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const RatingDemo = () => {
<Rating rating={ctrl.value} disabled={ctrl.disabled} onRatingChange={(value) => updateCtrl({value})} ariaLabelledBy="ratingLabel" />
<div id="form-msg" className="form-text small">
{ctrl.valid && <div className="text-success">Thanks!</div>}
{ctrl.invalid && <div className="text-danger">Please rate us</div>}
{ctrl.invalid && <div className="text-danger-emphasis">Please rate us</div>}
</div>
<pre>
Model:{' '}
Expand Down
6 changes: 6 additions & 0 deletions react/demo/src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="icon" type="image/svg+xml" href="./agnosui-logo.svg" />
<title>Vite App</title>
<script>
const theme = window.localStorage.getItem('theme');
if (theme === 'dark' || ((theme === 'auto' || !theme) && (window.parent ?? window).matchMedia('(prefers-color-scheme: dark)').matches)) {
document.documentElement.setAttribute('data-bs-theme', 'dark');
}
</script>
</head>
<body>
<div id="root"></div>
Expand Down
8 changes: 8 additions & 0 deletions react/demo/src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,14 @@ const router = createHashRouter([
},
]);

window.addEventListener('storage', (event) => {
if (event.key === 'theme') {
if (event.newValue) {
document.documentElement.setAttribute('data-bs-theme', event.newValue);
}
}
});

ReactDOM.createRoot(document.getElementById('root')!).render(
<React.StrictMode>
<div className="container p-3">
Expand Down
10 changes: 10 additions & 0 deletions svelte/demo/src/app/App.svelte
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
<script lang="ts">
import {onMount} from 'svelte';
import AppCommon from '../common/AppCommon.svelte';
import 'bootstrap/dist/css/bootstrap.css';
const componentsToBeProcessed = import.meta.glob('./samples/*/*.route.svelte');
onMount(() => {
window.addEventListener('storage', (event) => {
if (event.key === 'theme') {
if (event.newValue) {
document.documentElement.setAttribute('data-bs-theme', event.newValue);
}
}
});
});
</script>

<div class="container p-3">
Expand Down
6 changes: 6 additions & 0 deletions svelte/demo/src/app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="icon" type="image/svg+xml" href="../common/agnosui-logo.svg" />
<title>Svelte App</title>
<script>
const theme = window.localStorage.getItem('theme');
if (theme === 'dark' || ((theme === 'auto' || !theme) && (window.parent ?? window).matchMedia('(prefers-color-scheme: dark)').matches)) {
document.documentElement.setAttribute('data-bs-theme', 'dark');
}
</script>
</head>
<body>
<div id="root"></div>
Expand Down
2 changes: 1 addition & 1 deletion svelte/demo/src/app/samples/rating/Form.route.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<div class="text-success">Thanks!</div>
{/if}
{#if ctrl.invalid}
<div class="text-danger">Please rate us</div>
<div class="text-danger-emphasis">Please rate us</div>
{/if}
</div>
<pre>Model: <span id="form-model"><b>{ctrl.value}</b></span></pre>
Expand Down

0 comments on commit 1710af4

Please sign in to comment.