Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

[#45010] added option for regular labels

Eric Schubert1a888c694d0d
diff --git a/frontend/src/app/spot/components/selector-field/selector-field.component.html b/frontend/src/app/spot/components/selector-field/selector-field.component.html
index 0ab71c2ecf7..c2932b7b3ed 100644
--- a/frontend/src/app/spot/components/selector-field/selector-field.component.html
+++ b/frontend/src/app/spot/components/selector-field/selector-field.component.html
@@ -14,6 +14,9 @@
<div
*ngIf="label"
class="spot-form-field--label spot-selector-field--label"
+ [ngClass]="{
+ 'spot-selector-field--label_regular': labelWeight === 'regular'
+ }"
>
<span
*ngIf="showErrorMessage"
diff --git a/frontend/src/app/spot/components/selector-field/selector-field.component.ts b/frontend/src/app/spot/components/selector-field/selector-field.component.ts
index e27181d371c..be5c9e65ac9 100644
--- a/frontend/src/app/spot/components/selector-field/selector-field.component.ts
+++ b/frontend/src/app/spot/components/selector-field/selector-field.component.ts
@@ -34,6 +34,11 @@ export class SpotSelectorFieldComponent {
*/
@Input() reverseLabel = false;
+ /**
+ * Whether the label should be in bold or regular font weight
+ */
+ @Input() labelWeight:'bold'|'regular' = 'regular';
+
/**
* Whether this input is required
*/
@@ -43,7 +48,7 @@ export class SpotSelectorFieldComponent {
* When to show validation errors. To remain consistent, you will almost never need to change this.
* However, for some inputs or usecases it might be useful to show the validation error anyway.
*/
- @Input() showValidationErrorOn:'change' | 'blur' | 'submit' | 'never' = 'submit';
+ @Input() showValidationErrorOn:'change'|'blur'|'submit'|'never' = 'submit';
/**
* The control of the input. This can be any interface that is compatible with `AbstractControl`,
@@ -86,9 +91,11 @@ export class SpotSelectorFieldComponent {
if (this.showValidationErrorOn === 'submit') {
return this.formControl.invalid && this.formGroupDirective?.submitted;
- } if (this.showValidationErrorOn === 'blur') {
+ }
+ if (this.showValidationErrorOn === 'blur') {
return this.formControl.invalid && this.formControl.touched;
- } if (this.showValidationErrorOn === 'change') {
+ }
+ if (this.showValidationErrorOn === 'change') {
return this.formControl.invalid && this.formControl.dirty;
}
diff --git a/frontend/src/app/spot/components/selector-field/stories/SelectorField.example.html b/frontend/src/app/spot/components/selector-field/stories/SelectorField.example.html
new file mode 100644
index 00000000000..8f165030cbb
--- /dev/null
+++ b/frontend/src/app/spot/components/selector-field/stories/SelectorField.example.html
@@ -0,0 +1,46 @@
+<div class="spot-container">
+ <spot-selector-field [label]="'not checked'">
+ <spot-checkbox slot="input"></spot-checkbox>
+ </spot-selector-field>
+ <spot-selector-field [label]="'checked'">
+ <spot-checkbox
+ slot="input"
+ [checked]="true"
+ ></spot-checkbox>
+ </spot-selector-field>
+ <spot-selector-field [label]="'mixed'">
+ <spot-checkbox
+ slot="input"
+ [(ngModel)]="mixed"
+ ></spot-checkbox>
+ </spot-selector-field>
+ <spot-selector-field [label]="'disabled and checked'">
+ <spot-checkbox
+ slot="input"
+ [disabled]="true"
+ [checked]="true"
+ ></spot-checkbox>
+ </spot-selector-field>
+
+ <hr class="spot-divider">
+
+ <spot-selector-field [label]="'switched off'">
+ <spot-switch
+ slot="input"
+ [checked]="false"
+ ></spot-switch>
+ </spot-selector-field>
+ <spot-selector-field [label]="'switched on'">
+ <spot-switch
+ slot="input"
+ [checked]="true"
+ ></spot-switch>
+ </spot-selector-field>
+ <spot-selector-field [label]="'switched off and disabled'">
+ <spot-switch
+ slot="input"
+ [checked]="false"
+ [disabled]="true"
+ ></spot-switch>
+ </spot-selector-field>
+</div>
diff --git a/frontend/src/app/spot/components/selector-field/stories/SelectorField.example.ts b/frontend/src/app/spot/components/selector-field/stories/SelectorField.example.ts
new file mode 100644
index 00000000000..dc40185bb0b
--- /dev/null
+++ b/frontend/src/app/spot/components/selector-field/stories/SelectorField.example.ts
@@ -0,0 +1,10 @@
+import { ChangeDetectionStrategy, Component } from '@angular/core';
+import { SpotCheckboxState } from 'core-app/spot/components/checkbox/checkbox.component';
+
+@Component({
+ templateUrl: './SelectorField.example.html',
+ changeDetection: ChangeDetectionStrategy.OnPush,
+})
+export class SbSelectorFieldExample {
+ public mixed:SpotCheckboxState = null;
+}
diff --git a/frontend/src/app/spot/components/selector-field/stories/SelectorField.stories.mdx b/frontend/src/app/spot/components/selector-field/stories/SelectorField.stories.mdx
index 196ca1d2ecf..0e4ed0c426f 100644
--- a/frontend/src/app/spot/components/selector-field/stories/SelectorField.stories.mdx
+++ b/frontend/src/app/spot/components/selector-field/stories/SelectorField.stories.mdx
@@ -1,8 +1,11 @@
import { moduleMetadata } from '@storybook/angular';
+import { FormsModule } from '@angular/forms';
import { Canvas, Meta, Story, ArgsTable } from '@storybook/addon-docs';
import { OpSpotModule } from '../../../spot.module';
import { SpotSelectorFieldComponent } from '../selector-field.component';
+import { SbSelectorFieldExample } from './SelectorField.example';
+import { SbSelectorFieldFontWeightExample } from './SelectorFieldFontWeight.example';
<Meta
title="Patterns/Selector Field"
@@ -11,6 +14,7 @@ import { SpotSelectorFieldComponent } from '../selector-field.component';
moduleMetadata({
imports: [
OpSpotModule,
+ FormsModule,
],
}),
]}
@@ -22,20 +26,21 @@ import { SpotSelectorFieldComponent } from '../selector-field.component';
}}
/>
-
# Selector Field
-> Example: Checkbox with 3 items with hierarchy, showing 3 modes (mixed, checked and unchecked), and 2 states (enabled and disabled). A set of three radio buttons (unselected, selected, disabled).
+<Canvas>
+ <Story name="SelectorField example">
+ {{ component: SbSelectorFieldExample }}
+ </Story>
+</Canvas>
Selector fields are used to offer the user a number of different options.
-The selector field consists of either a checkbox or a radio button along with a label.
+The selector field consists of either a checkbox or a radio button along with a label.
-Checkboxes offer the possibility to make multiple selections.
+Checkboxes offer the possibility to make multiple selections.
Radio buttons require the user to choose only one from a list of options.
-<ArgsTable of={SpotSelectorFieldComponent} />
-
## Behaviour
The selector field extends the clickable zone of the checkbox or radio button to the entire label. Clicking on the label is then the same as clicking on the control element itself.
@@ -48,7 +53,11 @@ If the label text is particular long, it should wrap within the container, but b
Selector labels can be **bold** or regular. However, these two styles should not be mixed in a single set of selector fields.
-> Example: A selector field with a bold label and one that's regular
+<Canvas>
+ <Story name="SelectorField label font weight example">
+ {{ component: SbSelectorFieldFontWeightExample }}
+ </Story>
+</Canvas>
## States
@@ -60,4 +69,4 @@ The selector field itself only has two states, *enabled* and *disabled*.
Because the selector field itself is often placed in containers that have their own margins (like the action bar), it does not inherently have any margins of its own.
-Note however the 2 REM space between the element and the label.
+<ArgsTable of={SpotSelectorFieldComponent} />
diff --git a/frontend/src/app/spot/components/selector-field/stories/SelectorFieldFontWeight.example.html b/frontend/src/app/spot/components/selector-field/stories/SelectorFieldFontWeight.example.html
new file mode 100644
index 00000000000..ce8d572af2c
--- /dev/null
+++ b/frontend/src/app/spot/components/selector-field/stories/SelectorFieldFontWeight.example.html
@@ -0,0 +1,12 @@
+<div class="spot-container">
+ <spot-selector-field
+ [label]="'Bold Label'"
+ [labelWeight]="'bold'"
+ >
+ <spot-checkbox slot="input"></spot-checkbox>
+ </spot-selector-field>
+
+ <spot-selector-field [label]="'Regular Label'">
+ <spot-checkbox slot="input"></spot-checkbox>
+ </spot-selector-field>
+</div>
diff --git a/frontend/src/app/spot/components/selector-field/stories/SelectorFieldFontWeight.example.ts b/frontend/src/app/spot/components/selector-field/stories/SelectorFieldFontWeight.example.ts
new file mode 100644
index 00000000000..3f69704afdc
--- /dev/null
+++ b/frontend/src/app/spot/components/selector-field/stories/SelectorFieldFontWeight.example.ts
@@ -0,0 +1,10 @@
+import { ChangeDetectionStrategy, Component } from '@angular/core';
+import { SpotCheckboxState } from 'core-app/spot/components/checkbox/checkbox.component';
+
+@Component({
+ templateUrl: './SelectorFieldFontWeight.example.html',
+ changeDetection: ChangeDetectionStrategy.OnPush,
+})
+export class SbSelectorFieldFontWeightExample {
+ public mixed:SpotCheckboxState = null;
+}
diff --git a/frontend/src/app/spot/styles/sass/common/container.sass b/frontend/src/app/spot/styles/sass/common/container.sass
index 53d71999129..8db96398799 100644
--- a/frontend/src/app/spot/styles/sass/common/container.sass
+++ b/frontend/src/app/spot/styles/sass/common/container.sass
@@ -11,6 +11,8 @@
> .spot-body-small,
> .spot-caption,
> .spot-divider,
+ > .spot-selector-field,
+ > .spot-form-field,
> .spot-text-field
margin: $spot-spacing-1 $spot-spacing-1 0
diff --git a/frontend/src/app/spot/styles/sass/components/selector-field.sass b/frontend/src/app/spot/styles/sass/components/selector-field.sass
index 6ff6646079b..40e192ec5f2 100644
--- a/frontend/src/app/spot/styles/sass/components/selector-field.sass
+++ b/frontend/src/app/spot/styles/sass/components/selector-field.sass
@@ -26,6 +26,9 @@
grid-area: label
margin-bottom: 0
+ &_regular
+ font-weight: normal
+
&--description
margin-bottom: 0