mirror of
https://github.com/discourse/discourse.git
synced 2025-05-30 07:11:34 +08:00
DEV: various improvements to devex on chat (#21612)
- Improves styleguide support - Adds toggle color scheme to styleguide - Adds properties mutators to styleguide - Attempts to quit a session as soon as done with it in system specs, this should at least free resources faster - Refactors fabricators to simplify them - Adds more fabricators (uploads for example) - Starts implementing components pattern in system specs - Uses Chat::Message creator to create messages in system specs, this should help to have more real specs as the side effects should now happen
This commit is contained in:
@ -0,0 +1,3 @@
|
||||
<div class="component">
|
||||
{{yield}}
|
||||
</div>
|
@ -0,0 +1,3 @@
|
||||
import Component from "@glimmer/component";
|
||||
|
||||
export default class StyleguideComponent extends Component {}
|
@ -0,0 +1,5 @@
|
||||
<table class="component-properties">
|
||||
<tbody>
|
||||
{{yield}}
|
||||
</tbody>
|
||||
</table>
|
3
plugins/styleguide/assets/javascripts/discourse/components/styleguide/controls.js
vendored
Normal file
3
plugins/styleguide/assets/javascripts/discourse/components/styleguide/controls.js
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
import Component from "@glimmer/component";
|
||||
|
||||
export default class StyleguideControls extends Component {}
|
@ -0,0 +1,6 @@
|
||||
<tr class="component-properties__row">
|
||||
<td class="component-properties__cell">{{@name}}</td>
|
||||
<td class="component-properties__cell">
|
||||
{{yield}}
|
||||
</td>
|
||||
</tr>
|
@ -0,0 +1 @@
|
||||
<DToggleSwitch @state={{@enabled}} {{on "click" @action}} />
|
@ -0,0 +1,3 @@
|
||||
import Component from "@glimmer/component";
|
||||
|
||||
export default class StyleguideControlsToggle extends Component {}
|
@ -0,0 +1 @@
|
||||
<DButton @action={{this.toggle}} class="toggle-color-mode">Toggle color</DButton>
|
@ -0,0 +1,45 @@
|
||||
import Component from "@glimmer/component";
|
||||
import { action } from "@ember/object";
|
||||
import { inject as service } from "@ember/service";
|
||||
import { tracked } from "@glimmer/tracking";
|
||||
|
||||
const DARK = "dark";
|
||||
const LIGHT = "light";
|
||||
|
||||
function colorSchemeOverride(type) {
|
||||
const lightScheme = document.querySelector("link.light-scheme");
|
||||
const darkScheme = document.querySelector("link.dark-scheme");
|
||||
|
||||
if (!lightScheme || !darkScheme) {
|
||||
return;
|
||||
}
|
||||
|
||||
switch (type) {
|
||||
case DARK:
|
||||
lightScheme.media = "none";
|
||||
darkScheme.media = "all";
|
||||
break;
|
||||
case LIGHT:
|
||||
lightScheme.media = "all";
|
||||
darkScheme.media = "none";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
export default class ToggleColorMode extends Component {
|
||||
@service keyValueStore;
|
||||
|
||||
@tracked colorSchemeOverride = this.default;
|
||||
|
||||
get default() {
|
||||
return window.matchMedia("(prefers-color-scheme: dark)").matches
|
||||
? DARK
|
||||
: LIGHT;
|
||||
}
|
||||
|
||||
@action
|
||||
toggle() {
|
||||
this.colorSchemeOverride = this.colorSchemeOverride === DARK ? LIGHT : DARK;
|
||||
colorSchemeOverride(this.colorSchemeOverride);
|
||||
}
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
<section class="styleguide">
|
||||
<section class="styleguide-menu">
|
||||
<ToggleColorMode />
|
||||
{{#each this.categories as |c|}}
|
||||
<ul>
|
||||
<li class="styleguide-heading">{{i18n
|
||||
|
@ -73,6 +73,36 @@
|
||||
|
||||
.rendered {
|
||||
width: 100%;
|
||||
position: relative;
|
||||
|
||||
.component {
|
||||
padding: 2rem;
|
||||
border: 2px dotted var(--primary-low);
|
||||
margin-bottom: 2rem;
|
||||
}
|
||||
|
||||
.component-properties {
|
||||
width: 100%;
|
||||
|
||||
&__cell {
|
||||
padding: 0.5rem 0;
|
||||
|
||||
&:first-child {
|
||||
width: 30%;
|
||||
}
|
||||
|
||||
textarea,
|
||||
input {
|
||||
box-sizing: border-box;
|
||||
margin: 0;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
textarea {
|
||||
height: 100px;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
margin-bottom: 2em;
|
||||
|
Reference in New Issue
Block a user