Skip to content

Commit

Permalink
feat(core): add alignment property to radio, checkboxes and toggles (#…
Browse files Browse the repository at this point in the history
…548)

* feat(core): add alignment property to radio, checkboxes and toggles

* ci(core): fix ci

* feat(core): rename property values

---------

Co-authored-by: Tim Sielemann <[email protected]>
  • Loading branch information
TimSielemann and Tim Sielemann authored Aug 22, 2024
1 parent 11d6d4f commit 345bec9
Show file tree
Hide file tree
Showing 14 changed files with 159 additions and 5 deletions.
54 changes: 54 additions & 0 deletions angular/projects/catalyst-demo/src/app/app.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,58 @@ <h1>new datepicker & timepicker</h1>
hint="Depends on formControl state"
></cat-datepicker>
<formly-form [form]="form" [fields]="fields"></formly-form>
<cat-checkbox>
<div slot="label">
<div>LABEL START</div>
<div>Subline</div>
</div>
</cat-checkbox>
<cat-checkbox alignment="center">
<div slot="label">
<div>LABEL CENTER</div>
<div>Subline</div>
</div>
</cat-checkbox>
<cat-checkbox alignment="bottom">
<div slot="label">
<div>LABEL END</div>
<div>Subline</div>
</div>
</cat-checkbox>
<cat-toggle>
<div slot="label">
<div>LABEL START</div>
<div>Subline</div>
</div>
</cat-toggle>
<cat-toggle alignment="center">
<div slot="label">
<div>LABEL CENTER</div>
<div>Subline</div>
</div>
</cat-toggle>
<cat-toggle alignment="bottom">
<div slot="label">
<div>LABEL END</div>
<div>Subline</div>
</div>
</cat-toggle>
<cat-radio>
<div slot="label">
<div>LABEL START</div>
<div>Subline</div>
</div>
</cat-radio>
<cat-radio alignment="center">
<div slot="label">
<div>LABEL CENTER</div>
<div>Subline</div>
</div>
</cat-radio>
<cat-radio alignment="bottom">
<div slot="label">
<div>LABEL END</div>
<div>Subline</div>
</div>
</cat-radio>
</form>
11 changes: 9 additions & 2 deletions angular/projects/catalyst-demo/src/app/app.module.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
import { NgModule } from '@angular/core';
import { ReactiveFormsModule } from '@angular/forms';
import { BrowserModule } from '@angular/platform-browser';
import { CatalystModule } from '@haiilo/catalyst-angular';
import { FormlyModule } from '@ngx-formly/core';
import { CatalystFormlyModule } from '../../../catalyst-formly/src';
import { CatalystModule } from '../../../catalyst/src';
import { AppComponent } from './app.component';
import { DialogComponent } from './dialog/dialog.component';

@NgModule({
imports: [BrowserModule, ReactiveFormsModule, FormlyModule.forRoot(), CatalystModule.forRoot(), CatalystFormlyModule],
imports: [
BrowserModule,
ReactiveFormsModule,
FormlyModule.forRoot(),
CatalystModule.forRoot(),
CatalystFormlyModule,
CatalystModule
],
declarations: [AppComponent, DialogComponent],
bootstrap: [AppComponent]
})
Expand Down
6 changes: 6 additions & 0 deletions angular/projects/catalyst/src/lib/directives/proxies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ export declare interface CatCard extends Components.CatCard {

@ProxyCmp({
inputs: [
'alignment',
'checked',
'disabled',
'hint',
Expand All @@ -240,6 +241,7 @@ export declare interface CatCard extends Components.CatCard {
template: '<ng-content></ng-content>',
// eslint-disable-next-line @angular-eslint/no-inputs-metadata-property
inputs: [
'alignment',
'checked',
'disabled',
'hint',
Expand Down Expand Up @@ -795,6 +797,7 @@ export declare interface CatPagination extends Components.CatPagination {

@ProxyCmp({
inputs: [
'alignment',
'checked',
'disabled',
'hint',
Expand All @@ -815,6 +818,7 @@ export declare interface CatPagination extends Components.CatPagination {
template: '<ng-content></ng-content>',
// eslint-disable-next-line @angular-eslint/no-inputs-metadata-property
inputs: [
'alignment',
'checked',
'disabled',
'hint',
Expand Down Expand Up @@ -1324,6 +1328,7 @@ export declare interface CatTime extends Components.CatTime {

@ProxyCmp({
inputs: [
'alignment',
'checked',
'disabled',
'hint',
Expand All @@ -1346,6 +1351,7 @@ export declare interface CatTime extends Components.CatTime {
template: '<ng-content></ng-content>',
// eslint-disable-next-line @angular-eslint/no-inputs-metadata-property
inputs: [
'alignment',
'checked',
'disabled',
'hint',
Expand Down
24 changes: 24 additions & 0 deletions core/src/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,10 @@ export namespace Components {
* number of options.
*/
interface CatCheckbox {
/**
* The alignment of the checkbox.
*/
"alignment": 'center' | 'top' | 'bottom';
/**
* Checked state of the checkbox
*/
Expand Down Expand Up @@ -926,6 +930,10 @@ export namespace Components {
* only one of a predefined set of mutually exclusive options.
*/
interface CatRadio {
/**
* The alignment of the checkbox.
*/
"alignment": 'center' | 'top' | 'bottom';
/**
* Whether this radio is checked.
*/
Expand Down Expand Up @@ -1468,6 +1476,10 @@ export namespace Components {
* feature or option that can be turned on or off.
*/
interface CatToggle {
/**
* The alignment of the checkbox.
*/
"alignment": 'center' | 'top' | 'bottom';
/**
* Checked state of the toggle.
*/
Expand Down Expand Up @@ -2403,6 +2415,10 @@ declare namespace LocalJSX {
* number of options.
*/
interface CatCheckbox {
/**
* The alignment of the checkbox.
*/
"alignment"?: 'center' | 'top' | 'bottom';
/**
* Checked state of the checkbox
*/
Expand Down Expand Up @@ -3085,6 +3101,10 @@ declare namespace LocalJSX {
* only one of a predefined set of mutually exclusive options.
*/
interface CatRadio {
/**
* The alignment of the checkbox.
*/
"alignment"?: 'center' | 'top' | 'bottom';
/**
* Whether this radio is checked.
*/
Expand Down Expand Up @@ -3647,6 +3667,10 @@ declare namespace LocalJSX {
* feature or option that can be turned on or off.
*/
interface CatToggle {
/**
* The alignment of the checkbox.
*/
"alignment"?: 'center' | 'top' | 'bottom';
/**
* Checked state of the toggle.
*/
Expand Down
8 changes: 8 additions & 0 deletions core/src/components/cat-checkbox/cat-checkbox.scss
Original file line number Diff line number Diff line change
Expand Up @@ -142,3 +142,11 @@ input {
cursor: not-allowed;
color: cat-token('color.ui.font.muted');
}

.align-center {
align-items: center;
}

.align-end {
align-items: flex-end;
}
13 changes: 12 additions & 1 deletion core/src/components/cat-checkbox/cat-checkbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,11 @@ export class CatCheckbox {
*/
@Prop() labelLeft = false;

/**
* The alignment of the checkbox.
*/
@Prop() alignment: 'center' | 'top' | 'bottom' = 'top';

/**
* Attributes that will be added to the native HTML input element.
*/
Expand Down Expand Up @@ -155,7 +160,13 @@ export class CatCheckbox {
<Host>
<label
htmlFor={this.id}
class={{ 'is-hidden': this.labelHidden, 'is-disabled': this.disabled, 'label-left': this.labelLeft }}
class={{
'is-hidden': this.labelHidden,
'is-disabled': this.disabled,
'label-left': this.labelLeft,
'align-center': this.alignment === 'center',
'align-end': this.alignment === 'bottom'
}}
>
<input
{...this.nativeAttributes}
Expand Down
1 change: 1 addition & 0 deletions core/src/components/cat-checkbox/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ number of options.

| Property | Attribute | Description | Type | Default |
| ------------------ | ---------------- | ----------------------------------------------------------------------------------------- | ----------------------------------------- | ----------- |
| `alignment` | `alignment` | The alignment of the checkbox. | `"bottom" \| "center" \| "top"` | `'top'` |
| `checked` | `checked` | Checked state of the checkbox | `boolean` | `false` |
| `disabled` | `disabled` | Disabled state of the checkbox | `boolean` | `false` |
| `hint` | `hint` | Optional hint text(s) to be displayed with the checkbox. | `string \| string[] \| undefined` | `undefined` |
Expand Down
8 changes: 8 additions & 0 deletions core/src/components/cat-radio/cat-radio.scss
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,11 @@ input {
background-color: cat-token('color.ui.border.dark');
}
}

.align-center .radio {
align-self: center;
}

.align-end .radio {
align-self: flex-end;
}
13 changes: 12 additions & 1 deletion core/src/components/cat-radio/cat-radio.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ export class CatRadio {
*/
@Prop() labelLeft = false;

/**
* The alignment of the checkbox.
*/
@Prop() alignment: 'center' | 'top' | 'bottom' = 'top';

/**
* Attributes that will be added to the native HTML input element.
*/
Expand Down Expand Up @@ -133,7 +138,13 @@ export class CatRadio {
<Host>
<label
htmlFor={this.id}
class={{ 'is-hidden': this.labelHidden, 'is-disabled': this.disabled, 'label-left': this.labelLeft }}
class={{
'is-hidden': this.labelHidden,
'is-disabled': this.disabled,
'label-left': this.labelLeft,
'align-center': this.alignment === 'center',
'align-end': this.alignment === 'bottom'
}}
role="radio"
aria-checked={this.checked ? 'true' : 'false'}
>
Expand Down
1 change: 1 addition & 0 deletions core/src/components/cat-radio/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ only one of a predefined set of mutually exclusive options.

| Property | Attribute | Description | Type | Default |
| ------------------ | -------------- | ----------------------------------------------------------------------------------------- | ----------------------------------------- | ----------- |
| `alignment` | `alignment` | The alignment of the checkbox. | `"bottom" \| "center" \| "top"` | `'top'` |
| `checked` | `checked` | Whether this radio is checked. | `boolean` | `false` |
| `disabled` | `disabled` | Whether this radio is disabled. | `boolean` | `false` |
| `hint` | `hint` | Optional hint text(s) to be displayed with the radio. | `string \| string[] \| undefined` | `undefined` |
Expand Down
8 changes: 8 additions & 0 deletions core/src/components/cat-toggle/cat-toggle.scss
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,11 @@ input {
cursor: not-allowed;
color: cat-token('color.ui.font.muted');
}

.align-center {
align-items: center;
}

.align-end {
align-items: flex-end;
}
13 changes: 12 additions & 1 deletion core/src/components/cat-toggle/cat-toggle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ export class CatToggle {
*/
@Prop() labelLeft = false;

/**
* The alignment of the checkbox.
*/
@Prop() alignment: 'center' | 'top' | 'bottom' = 'top';

/**
* Attributes that will be added to the native HTML input element.
*/
Expand Down Expand Up @@ -150,7 +155,13 @@ export class CatToggle {
<Host>
<label
htmlFor={this.id}
class={{ 'is-hidden': this.labelHidden, 'is-disabled': this.disabled, 'label-left': this.labelLeft }}
class={{
'is-hidden': this.labelHidden,
'is-disabled': this.disabled,
'label-left': this.labelLeft,
'align-center': this.alignment === 'center',
'align-end': this.alignment === 'bottom'
}}
>
<input
{...this.nativeAttributes}
Expand Down
1 change: 1 addition & 0 deletions core/src/components/cat-toggle/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ feature or option that can be turned on or off.

| Property | Attribute | Description | Type | Default |
| ------------------ | ---------------- | ----------------------------------------------------------------------------------------- | ----------------------------------------- | ----------- |
| `alignment` | `alignment` | The alignment of the checkbox. | `"bottom" \| "center" \| "top"` | `'top'` |
| `checked` | `checked` | Checked state of the toggle. | `boolean` | `false` |
| `disabled` | `disabled` | Disabled state of the toggle. | `boolean` | `false` |
| `hint` | `hint` | Optional hint text(s) to be displayed with the toggle. | `string \| string[] \| undefined` | `undefined` |
Expand Down
3 changes: 3 additions & 0 deletions vue/src/components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ export const CatCheckbox = /*@__PURE__*/ defineContainer<JSX.CatCheckbox>('cat-c
'resolvedValue',
'hint',
'labelLeft',
'alignment',
'nativeAttributes',
'catChange',
'catFocus',
Expand Down Expand Up @@ -283,6 +284,7 @@ export const CatRadio = /*@__PURE__*/ defineContainer<JSX.CatRadio>('cat-radio',
'value',
'hint',
'labelLeft',
'alignment',
'nativeAttributes',
'catChange',
'catFocus',
Expand Down Expand Up @@ -454,6 +456,7 @@ export const CatToggle = /*@__PURE__*/ defineContainer<JSX.CatToggle>('cat-toggl
'resolvedValue',
'hint',
'labelLeft',
'alignment',
'nativeAttributes',
'catChange',
'catFocus',
Expand Down

0 comments on commit 345bec9

Please sign in to comment.