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

start writing in-ts docs

Benjamin Bädorf754b7af9c9ad
diff --git a/frontend/src/app/spot/components/checkbox/checkbox.component.ts b/frontend/src/app/spot/components/checkbox/checkbox.component.ts
index ea5374310d2..f60f425424c 100644
--- a/frontend/src/app/spot/components/checkbox/checkbox.component.ts
+++ b/frontend/src/app/spot/components/checkbox/checkbox.component.ts
@@ -32,16 +32,34 @@ export class SpotCheckboxComponent implements ControlValueAccessor {
@ViewChild('input') public input:ElementRef;
+ /**
+ * The tabindex for the underlying HTML input
+ */
@Input() tabindex = 0;
+ /**
+ * Whether the input should be disabled
+ */
@Input() disabled = false;
+ /**
+ * The name of the input. Will be autogenerated if not given,
+ * but especially useful to provide in a hybrid Rails <-> Angular context
+ * where a submit of a form is handled without JS.
+ */
@Input() name = `spot-checkbox-${+(new Date())}`;
- @Output() checkedChange = new EventEmitter<boolean>();
-
+ /**
+ * If you're not using Angular Reactive Forms (Which you should be using!)
+ * then you can manually set the checked state via this input.
+ */
@Input() public checked = false;
+ /**
+ * Emits when the checked state changes.
+ */
+ @Output() checkedChange = new EventEmitter<boolean>();
+
constructor(
readonly cdRef:ChangeDetectorRef,
) {}
diff --git a/frontend/src/app/spot/components/drop-modal/drop-modal.component.ts b/frontend/src/app/spot/components/drop-modal/drop-modal.component.ts
index bad731d70d7..330efe57270 100644
--- a/frontend/src/app/spot/components/drop-modal/drop-modal.component.ts
+++ b/frontend/src/app/spot/components/drop-modal/drop-modal.component.ts
@@ -21,12 +21,21 @@ import { findAllFocusableElementsWithin } from 'core-app/shared/helpers/focus-he
export class SpotDropModalComponent implements OnDestroy {
@HostBinding('class.spot-drop-modal') public className = true;
- @Output() closed = new EventEmitter<void>();
-
+ /**
+ * The alignment of the drop modal. There are twelve alignments in total. You can check which ones they are
+ * from the `SpotDropAlignmentOption` Enum that is available in 'core-app/spot/drop-alignment-options'.
+ */
@Input() public alignment:SpotDropAlignmentOption = SpotDropAlignmentOption.BottomLeft;
+ get alignmentClass():string {
+ return `spot-drop-modal--body_${this.alignment}`;
+ }
+
public _open = false;
+ /**
+ * Boolean indicating whether the modal should be opened
+ */
@Input('open')
@HostBinding('class.spot-drop-modal_opened')
set open(value:boolean) {
@@ -60,9 +69,25 @@ export class SpotDropModalComponent implements OnDestroy {
return this._open;
}
- get alignmentClass():string {
- return `spot-drop-modal--body_${this.alignment}`;
- }
+ /**
+ * Emits when the drop modal closes. This is needed because you are usually controlling the opened
+ * state of the modal manually because you have to define the trigger that opens the modal, but can
+ * will close itself automatically if the user interacts outside of it or presses Escape.
+ *
+ * ```
+ * <spot-drop-modal
+ * [open]="isDropModalOpen"
+ * (closed)="isDropModalOpen = false"
+ * >
+ * <button
+ * slot="trigger"
+ * type="button"
+ * (click)="isDropModalOpen = true"
+ * >Open drop modal</button>
+ * </spot-drop-modal>
+ * ```
+ */
+ @Output() closed = new EventEmitter<void>();
public text = {
close: this.i18n.t('js.spot.drop_modal.close'),
diff --git a/frontend/src/app/spot/components/drop-modal/stories/DropModalList.component.ts b/frontend/src/app/spot/components/drop-modal/stories/DropModalList.component.ts
index f0c72b5c936..dbf67ecb42d 100644
--- a/frontend/src/app/spot/components/drop-modal/stories/DropModalList.component.ts
+++ b/frontend/src/app/spot/components/drop-modal/stories/DropModalList.component.ts
@@ -12,8 +12,6 @@ import SpotDropAlignmentOption from '../../../drop-alignment-options';
templateUrl: './DropModalList.component.html',
})
export class SbDropModalListComponent {
- @HostBinding('class.spot-drop-modal') public className = true;
-
@Input() public alignment:SpotDropAlignmentOption = SpotDropAlignmentOption.BottomLeft;
@Input('open') public dropModalOpen = false;
diff --git a/frontend/src/app/spot/components/form-field/form-field.component.ts b/frontend/src/app/spot/components/form-field/form-field.component.ts
index ca64c687c07..ce1e9c2c009 100644
--- a/frontend/src/app/spot/components/form-field/form-field.component.ts
+++ b/frontend/src/app/spot/components/form-field/form-field.component.ts
@@ -16,18 +16,49 @@ export class SpotFormFieldComponent {
return this.showErrorMessage;
}
+ /**
+ * The text label of the input
+ */
@Input() label = '';
+ /**
+ * By default, the label wraps the input. For some input types this
+ * leads to unwanted behavior because clicking in the input might focus
+ * unrelated elements.
+ *
+ * One example of an input like is the CKEditor rich text editor.
+ *
+ * Setting noWrapLabel to `true` causes the label not to wrap the input.
+ * This might slighly reduce the label functionality (e.g. clicking the label
+ * does not focus the input) but is still preferred over more broken behavior.
+ */
@Input() noWrapLabel = false;
+ /**
+ * Whether this input is required
+ */
@Input() required = false;
- @Input() hidden = false;
-
+ /**
+ * 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';
+ /**
+ * The control of the input. This can be any interface that is compatible with `AbstractControl`,
+ * but will almost always be a `FormControl`.
+ *
+ * The control is used to show disabled and invalid states.
+ */
@Input() control?:AbstractControl;
+ /**
+ * Hides the input. This is a utility input for usage of `spot-form-field` in dynamic forms.
+ * Outisde of dynamic forms, you should be hiding inputs via `*ngIf` or other methods.
+ */
+ @Input() hidden = false;
+
@ContentChild(NgControl) ngControl:NgControl;
internalID = `spot-form-field-${+new Date()}`;
diff --git a/frontend/src/app/spot/components/form-field/stories/FormField.stories.mdx b/frontend/src/app/spot/components/form-field/stories/FormField.stories.mdx
index d873430b69c..8c267ec9418 100644
--- a/frontend/src/app/spot/components/form-field/stories/FormField.stories.mdx
+++ b/frontend/src/app/spot/components/form-field/stories/FormField.stories.mdx
@@ -22,7 +22,6 @@ import { SpotFormFieldComponent } from '../form-field.component';
}}
/>
-
# Form Field
<ArgsTable of={SpotFormFieldComponent} />
diff --git a/frontend/src/app/spot/components/form-field/stories/FormFieldBasic.example.html b/frontend/src/app/spot/components/form-field/stories/FormFieldBasic.example.html
new file mode 100644
index 00000000000..8ac5222eef4
--- /dev/null
+++ b/frontend/src/app/spot/components/form-field/stories/FormFieldBasic.example.html
@@ -0,0 +1,8 @@
+<spot-form-field
+ [label]="label"
+ [disabled]="disabled"
+>
+ <spot-text-field
+ slot="input"
+ ></spot-text-field>
+</spot-form-field>
diff --git a/frontend/src/app/spot/components/form-field/stories/FormFieldBasic.example.ts b/frontend/src/app/spot/components/form-field/stories/FormFieldBasic.example.ts
new file mode 100644
index 00000000000..288525dd513
--- /dev/null
+++ b/frontend/src/app/spot/components/form-field/stories/FormFieldBasic.example.ts
@@ -0,0 +1,14 @@
+import {
+ Component,
+ Input,
+} from '@angular/core';
+
+@Component({
+ selector: 'sb-form-field-basic',
+ templateUrl: './FormFieldBasic.example.html',
+})
+export class SbFormFieldBasicExampleComponent {
+ @Input('label') public label = '';
+ @Input('disabled') public disabled = false;
+ @Input('open') public dropModalOpen = false;
+}
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 f4ccaae80f3..f626a5784d2 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
@@ -24,18 +24,41 @@ export class SpotSelectorFieldComponent {
return this.showErrorMessage;
}
+ /**
+ * The text label of the input
+ */
@Input() label = '';
+ /**
+ * Whether the label should be in front of the input instead of after it
+ */
@Input() reverseLabel = false;
- @Input() hidden = false;
-
+ /**
+ * Whether this input is required
+ */
@Input() required = false;
+ /**
+ * 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';
+ /**
+ * The control of the input. This can be any interface that is compatible with `AbstractControl`,
+ * but will almost always be a `FormControl`.
+ *
+ * The control is used to show disabled and invalid states.
+ */
@Input() control?:AbstractControl;
+ /**
+ * Hides the input. This is a utility input for usage of `spot-form-field` in dynamic forms.
+ * Outisde of dynamic forms, you should be hiding inputs via `*ngIf` or other methods.
+ */
+ @Input() hidden = false;
+
@ContentChild(NgControl) ngControl:NgControl;
internalID = `spot-selector-field-${+new Date()}`;
diff --git a/frontend/src/app/spot/components/switch/switch.component.ts b/frontend/src/app/spot/components/switch/switch.component.ts
index 464351b2ec1..f0e549b1b5e 100644
--- a/frontend/src/app/spot/components/switch/switch.component.ts
+++ b/frontend/src/app/spot/components/switch/switch.component.ts
@@ -35,16 +35,34 @@ export class SpotSwitchComponent implements ControlValueAccessor {
@ViewChild('input') public input:ElementRef;
+ /**
+ * The tabindex for the underlying HTML input
+ */
@Input() tabindex = 0;
+ /**
+ * Whether the input should be disabled
+ */
@Input() disabled = false;
+ /**
+ * The name of the input. Will be autogenerated if not given,
+ * but especially useful to provide in a hybrid Rails <-> Angular context
+ * where a submit of a form is handled without JS.
+ */
@Input() name = `spot-switch-${+(new Date())}`;
- @Output() checkedChange = new EventEmitter<boolean>();
-
+ /**
+ * If you're not using Angular Reactive Forms (Which you should be using!)
+ * then you can manually set the checked state via this input.
+ */
@Input() public checked = false;
+ /**
+ * Emits when the checked state changes.
+ */
+ @Output() checkedChange = new EventEmitter<boolean>();
+
constructor(
public elementRef:ElementRef,
public cdRef:ChangeDetectorRef,
diff --git a/frontend/src/app/spot/components/text-field/text-field.component.ts b/frontend/src/app/spot/components/text-field/text-field.component.ts
index 37fb92d8d64..2c2f9c1dd62 100644
--- a/frontend/src/app/spot/components/text-field/text-field.component.ts
+++ b/frontend/src/app/spot/components/text-field/text-field.component.ts
@@ -36,10 +36,21 @@ export class SpotTextFieldComponent implements ControlValueAccessor {
@ViewChild('input') public input:ElementRef;
+ /**
+ * The name of the input. Will be autogenerated if not given,
+ * but especially useful to provide in a hybrid Rails <-> Angular context
+ * where a submit of a form is handled without JS.
+ */
@Input() name = `spot-text-field-${+(new Date())}`;
+ /**
+ * Whether the input should be disabled
+ */
@Input() @HostBinding('class.spot-text-field_disabled') public disabled = false;
+ /**
+ *
+ */
@Input() showClearButton = true;
@Input() public placeholder = '';
diff --git a/frontend/src/app/spot/components/toggle/stories/Toggle.stories.mdx b/frontend/src/app/spot/components/toggle/stories/Toggle.stories.mdx
index 227ef4d4483..e308cb97bd5 100644
--- a/frontend/src/app/spot/components/toggle/stories/Toggle.stories.mdx
+++ b/frontend/src/app/spot/components/toggle/stories/Toggle.stories.mdx
@@ -26,6 +26,15 @@ import { SpotToggleComponent } from '../toggle.component';
Some text here.
+export const Template = ({ name, value, options }) => {
+ return {
+ props: { name, value, options },
+ parameters: {
+ layout: 'centered',
+ },
+ };
+};
+
<Canvas>
<Story
name="Preset value"
@@ -43,15 +52,6 @@ Some text here.
<ArgsTable of={SpotToggleComponent} />
-export const Template = ({ name, value, options }) => {
- return {
- props: { name, value, options },
- parameters: {
- layout: 'centered',
- },
- };
-};
-
<Canvas>
<Story
name="Preset value 2"