Skip to content

Commit 227083a

Browse files
authored
fix(radio, toggle): multiline support (#DS-3538) (#657)
1 parent 199fefb commit 227083a

File tree

17 files changed

+219
-69
lines changed

17 files changed

+219
-69
lines changed

packages/components-dev/radio/module.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { ThemePalette } from '@koobiq/components/core';
44
import { KbqFormFieldModule } from '@koobiq/components/form-field';
55
import { KbqRadioChange, KbqRadioModule } from '@koobiq/components/radio';
66
import { RadioExamplesModule } from 'packages/docs-examples/components/radio';
7+
import { DevThemeToggle } from '../theme-toggle';
78

89
@Component({
910
standalone: true,
@@ -17,6 +18,8 @@ import { RadioExamplesModule } from 'packages/docs-examples/components/radio';
1718
<radio-content-example />
1819
<hr />
1920
<radio-group-example />
21+
<hr />
22+
<radio-multiline-example />
2023
`,
2124
changeDetection: ChangeDetectionStrategy.OnPush
2225
})
@@ -28,7 +31,8 @@ export class DevRadioExamples {}
2831
FormsModule,
2932
KbqFormFieldModule,
3033
KbqRadioModule,
31-
DevRadioExamples
34+
DevRadioExamples,
35+
DevThemeToggle
3236
],
3337
selector: 'app',
3438
templateUrl: './template.html',

packages/components-dev/radio/template.html

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
<dev-theme-toggle />
2+
3+
<hr />
4+
5+
<dev-radio-examples />
6+
7+
<hr />
8+
19
<div class="layout-row">
210
<div class="dev-container layout-padding-right-xl">
311
<kbq-radio-group [(ngModel)]="favoriteFruit" (change)="onChange($event)">
@@ -83,7 +91,3 @@
8391
</kbq-radio-group>
8492
</div>
8593
</div>
86-
87-
<hr />
88-
89-
<dev-radio-examples />
Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1-
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
2-
import { DemoModule } from './module';
1+
import { bootstrapApplication } from '@angular/platform-browser';
2+
import { provideAnimations } from '@angular/platform-browser/animations';
3+
import { ToggleDev } from './module';
34

4-
platformBrowserDynamic()
5-
.bootstrapModule(DemoModule)
6-
.catch((error) => console.error(error));
5+
bootstrapApplication(ToggleDev, {
6+
providers: [
7+
provideAnimations()
8+
]
9+
}).catch((error) => console.error(error));

packages/components-dev/toggle/module.ts

Lines changed: 32 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,43 @@
1-
import { Component, NgModule, ViewEncapsulation } from '@angular/core';
1+
import { JsonPipe } from '@angular/common';
2+
import { ChangeDetectionStrategy, Component, ViewEncapsulation } from '@angular/core';
23
import { FormsModule, ReactiveFormsModule, UntypedFormControl } from '@angular/forms';
3-
import { BrowserModule } from '@angular/platform-browser';
4-
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
4+
import { KbqButtonModule } from '@koobiq/components/button';
55
import { ThemePalette } from '@koobiq/components/core';
66
import { KbqFormFieldModule } from '@koobiq/components/form-field';
7-
import { KbqButtonModule } from '../../components/button/';
8-
import { KbqToggleModule } from '../../components/toggle/';
7+
import { KbqToggleModule } from '@koobiq/components/toggle';
8+
import { ToggleExamplesModule } from 'packages/docs-examples/components/toggle';
9+
import { DevThemeToggle } from '../theme-toggle';
910

1011
@Component({
12+
standalone: true,
13+
imports: [ToggleExamplesModule],
14+
selector: 'dev-toggle-examples',
15+
template: `
16+
<toggle-multiline-example />
17+
`,
18+
changeDetection: ChangeDetectionStrategy.OnPush
19+
})
20+
export class DevToggleExamples {}
21+
22+
@Component({
23+
standalone: true,
1124
selector: 'app',
25+
imports: [
26+
FormsModule,
27+
KbqToggleModule,
28+
KbqButtonModule,
29+
KbqFormFieldModule,
30+
ReactiveFormsModule,
31+
JsonPipe,
32+
DevToggleExamples,
33+
DevThemeToggle
34+
],
1235
templateUrl: './template.html',
13-
styleUrls: ['./styles.scss'],
14-
encapsulation: ViewEncapsulation.None
36+
styleUrl: './styles.scss',
37+
encapsulation: ViewEncapsulation.None,
38+
changeDetection: ChangeDetectionStrategy.OnPush
1539
})
16-
export class DemoComponent {
40+
export class ToggleDev {
1741
themePalette = ThemePalette;
1842

1943
valueSmallOff: boolean = false;
@@ -30,22 +54,3 @@ export class DemoComponent {
3054
this.toggleControl.valueChanges.subscribe(console.log);
3155
}
3256
}
33-
34-
@NgModule({
35-
declarations: [
36-
DemoComponent
37-
],
38-
imports: [
39-
BrowserModule,
40-
BrowserAnimationsModule,
41-
FormsModule,
42-
KbqToggleModule,
43-
KbqButtonModule,
44-
KbqFormFieldModule,
45-
ReactiveFormsModule
46-
],
47-
bootstrap: [
48-
DemoComponent
49-
]
50-
})
51-
export class DemoModule {}

packages/components-dev/toggle/template.html

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
<dev-theme-toggle />
2+
3+
<hr />
4+
5+
<dev-toggle-examples />
6+
7+
<hr />
8+
19
<div class="container">
210
<h1>Toggles</h1>
311
<kbq-toggle [formControl]="toggleControl" />

packages/components/radio/radio.en.md

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,5 @@
1-
`<kbq-radio>` provides the same functionality as a native `<input type="radio">`.
1+
🚧 **Documentation in progress** 🚧
22

3-
<!-- example(radio-overview) -->
3+
Unfortunately, the documentation for this section is not ready yet. We are actively working on its creation and plan to add it soon.
44

5-
### Radio groups
6-
7-
Radio-buttons should typically be placed inside of an `<kbq-radio-group>` unless the DOM structure
8-
would make that impossible (e.g., radio-buttons inside of table cells). The radio-group has a
9-
`value` property that reflects the currently selected radio-button inside of the group.
10-
11-
Individual radio-buttons inside of a radio-group will inherit the `name` of the group.
12-
13-
### Use with @angular/forms
14-
15-
`<kbq-radio-group>` is compatible with `@angular/forms` and supports both `FormsModule`
16-
and `ReactiveFormsModule`.
17-
18-
### Accessibility
19-
20-
The `<kbq-radio-button>` uses an internal `<input type="radio">` to provide an accessible experience.
21-
This internal radio button receives focus and is automatically labelled by the text content of the
22-
`<kbq-radio-button>` element.
5+
If you would like to contribute to the documentation or have any questions, please feel free to [open an issue](https://github.com/koobiq/angular-components/issues) in our GitHub repository.

packages/components/radio/radio.ru.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@
2020

2121
<!-- example(radio-group) -->
2222

23+
#### Многострочный
24+
25+
<!-- example(radio-multiline) -->
26+
2327
### Рекомендации
2428

2529
- По умолчанию рекомендуется использовать до 7 вариантов в Radio Group.

packages/components/radio/radio.scss

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727

2828
cursor: pointer;
2929

30-
white-space: nowrap;
3130
// for maximum clickable area.
3231
width: 100%;
3332
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
11
<!-- example(toggle-overview) -->
2+
3+
### Многострочный
4+
5+
<!-- example(toggle-multiline) -->

packages/docs-examples/components/radio/index.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
import { NgModule } from '@angular/core';
22
import { RadioContentExample } from './radio-content/radio-content-example';
33
import { RadioGroupExample } from './radio-group/radio-group-example';
4+
import { RadioMultilineExample } from './radio-multiline/radio-multiline-example';
45
import { RadioSizeExample } from './radio-size/radio-size-example';
56
import { RadioStyleExample } from './radio-style/radio-style-example';
67

7-
export { RadioContentExample, RadioGroupExample, RadioSizeExample, RadioStyleExample };
8+
export { RadioContentExample, RadioGroupExample, RadioMultilineExample, RadioSizeExample, RadioStyleExample };
89

910
const EXAMPLES = [
1011
RadioSizeExample,
1112
RadioStyleExample,
1213
RadioContentExample,
13-
RadioGroupExample
14+
RadioGroupExample,
15+
RadioMultilineExample
1416
];
1517

1618
@NgModule({

packages/docs-examples/components/radio/radio-group/radio-group-example.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Component } from '@angular/core';
1+
import { ChangeDetectionStrategy, Component } from '@angular/core';
22
import { KbqRadioModule } from '@koobiq/components/radio';
33

44
/**
@@ -23,6 +23,7 @@ import { KbqRadioModule } from '@koobiq/components/radio';
2323
2424
<kbq-radio-button [disabled]="true" [value]="'option_5'">Item 5 (Disabled)</kbq-radio-button>
2525
</kbq-radio-group>
26-
`
26+
`,
27+
changeDetection: ChangeDetectionStrategy.OnPush
2728
})
2829
export class RadioGroupExample {}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import { ChangeDetectionStrategy, Component } from '@angular/core';
2+
import { KbqFormFieldModule } from '@koobiq/components/form-field';
3+
import { KbqRadioModule } from '@koobiq/components/radio';
4+
5+
type ExampleOption = { label: string; hint: string };
6+
7+
/**
8+
* @title Radio multiline example
9+
*/
10+
@Component({
11+
standalone: true,
12+
selector: 'radio-multiline-example',
13+
imports: [KbqRadioModule, KbqFormFieldModule],
14+
template: `
15+
<kbq-radio-group>
16+
@for (option of options; track option) {
17+
<kbq-radio-button [checked]="$first" [value]="$index">
18+
{{ option.label }}
19+
<kbq-hint>{{ option.hint }}</kbq-hint>
20+
</kbq-radio-button>
21+
}
22+
</kbq-radio-group>
23+
`,
24+
styles: `
25+
:host {
26+
display: flex;
27+
justify-content: center;
28+
}
29+
30+
.kbq-radio-group {
31+
max-width: 255px;
32+
}
33+
`,
34+
changeDetection: ChangeDetectionStrategy.OnPush
35+
})
36+
export class RadioMultilineExample {
37+
readonly options: ExampleOption[] = [
38+
{
39+
label: 'Regular software and operating system updates',
40+
hint: 'Updating software and operating systems regularly helps to patch vulnerabilities and enhance security measures against potential threats'
41+
},
42+
{
43+
label: 'Using strong and unique passwords',
44+
hint: 'Creating strong and unique passwords for each online account can enhance cybersecurity, as cyber attacks often exploit weak or stolen passwords'
45+
},
46+
{
47+
label: 'Implementing multi-factor authentication (MFA)',
48+
hint: 'Multi-factor authentication involves multiple identification forms before account access, reducing the risk of unauthorized access'
49+
}
50+
];
51+
}

packages/docs-examples/components/radio/radio-size/radio-size-example.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Component } from '@angular/core';
1+
import { ChangeDetectionStrategy, Component } from '@angular/core';
22
import { KbqRadioModule } from '@koobiq/components/radio';
33

44
/**
@@ -43,6 +43,7 @@ import { KbqRadioModule } from '@koobiq/components/radio';
4343
</div>
4444
</div>
4545
</div>
46-
`
46+
`,
47+
changeDetection: ChangeDetectionStrategy.OnPush
4748
})
4849
export class RadioSizeExample {}

packages/docs-examples/components/radio/radio-style/radio-style-example.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Component } from '@angular/core';
1+
import { ChangeDetectionStrategy, Component } from '@angular/core';
22
import { ThemePalette } from '@koobiq/components/core';
33
import { KbqRadioModule } from '@koobiq/components/radio';
44

@@ -54,7 +54,8 @@ import { KbqRadioModule } from '@koobiq/components/radio';
5454
</div>
5555
</div>
5656
</div>
57-
`
57+
`,
58+
changeDetection: ChangeDetectionStrategy.OnPush
5859
})
5960
export class RadioStyleExample {
6061
protected readonly themePalette = ThemePalette;

packages/docs-examples/components/toggle/index.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import { NgModule } from '@angular/core';
2+
import { ToggleMultilineExample } from './toggle-multiline/toggle-multiline-example';
23
import { ToggleOverviewExample } from './toggle-overview/toggle-overview-example';
34

4-
export { ToggleOverviewExample };
5+
export { ToggleMultilineExample, ToggleOverviewExample };
56

67
const EXAMPLES = [
7-
ToggleOverviewExample
8+
ToggleOverviewExample,
9+
ToggleMultilineExample
810
];
911

1012
@NgModule({
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { ChangeDetectionStrategy, Component } from '@angular/core';
2+
import { KbqFormFieldModule } from '@koobiq/components/form-field';
3+
import { KbqToggleModule } from '@koobiq/components/toggle';
4+
5+
/**
6+
* @title Toggle multiline example
7+
*/
8+
@Component({
9+
standalone: true,
10+
selector: 'toggle-multiline-example',
11+
imports: [KbqToggleModule, KbqFormFieldModule],
12+
template: `
13+
<kbq-toggle>
14+
I accept the security policy terms and acknowledge the responsibility to safeguard sensitive information
15+
<kbq-hint>
16+
Please review our security policy for detailed information about data protection and privacy standards.
17+
By checking this box, you confirm that you understand and agree to comply with all security
18+
requirements.
19+
</kbq-hint>
20+
</kbq-toggle>
21+
`,
22+
styles: `
23+
:host {
24+
display: flex;
25+
justify-content: center;
26+
}
27+
28+
.kbq-toggle {
29+
max-width: 400px;
30+
}
31+
`,
32+
changeDetection: ChangeDetectionStrategy.OnPush
33+
})
34+
export class ToggleMultilineExample {}

0 commit comments

Comments
 (0)