Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor Forms package to use BEM CSS naming #64

Merged
merged 3 commits into from
Apr 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions packages/forms/addon/components/form-checkbox-group.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
@isSmall={{@isSmall}}
@isLarge={{@isLarge}}
class="form-checkbox-group-container
{{if this.showErrorFeedback "has-error"}}
{{if @isInline "is-inline"}} {{@containerClass}}
{{if @isSmall "form-checkbox-group-container-sm" (if @isLarge "form-checkbox-group-container-lg")}}"
{{if @isInline "form-checkbox-group-container--inline"}} {{@containerClass}}
{{if @isSmall "form-checkbox-group-container--sm" (if @isLarge "form-checkbox-group-container--lg")}}"
role="group"
...attributes
as |f|
Expand Down
9 changes: 3 additions & 6 deletions packages/forms/addon/components/form-checkbox.hbs
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
<FormField
@isSmall={{@isSmall}}
@isLarge={{@isLarge}}
class="form-checkbox-container {{@containerClass}} {{if @isSmall "form-checkbox-container-sm" (if @isLarge "form-checkbox-container-lg")}}"
class="form-checkbox-container {{@containerClass}} {{if @isSmall "form-checkbox-container--sm" (if @isLarge "form-checkbox-container--lg")}}"
as |f|
>
<div class="label-container">
<div class="input-container">
<div class="form-checkbox-container__label-container">
<div class="form-checkbox-container__input-container">
{{!-- Zero-width space character, used to align checkbox properly --}}
&#8203;
<f.Checkbox
{{on "focus" this.handleFocusIn}}
{{on "blur" this.handleFocusOut}}

@onChange={{this.handleChange}}
@checked={{@checked}}
@name={{@name}}
Expand Down
13 changes: 0 additions & 13 deletions packages/forms/addon/components/form-checkbox.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import Component from '@glimmer/component';
import { action } from '@ember/object';
import { tracked } from '@glimmer/tracking';

interface FormCheckboxArgs {
label?: string;
Expand All @@ -19,8 +18,6 @@ interface FormCheckboxArgs {
}

export default class FormCheckbox extends Component<FormCheckboxArgs> {
@tracked isFocused = false;

@action handleChange(value: boolean, event: Event): void {
if (typeof this.args.onChange === 'function') {
this.args.onChange(value, event);
Expand All @@ -30,14 +27,4 @@ export default class FormCheckbox extends Component<FormCheckboxArgs> {
this.args._parentOnChange(value, event);
}
}

@action handleFocusIn(event: FocusEvent): void {
if (event.relatedTarget !== null) {
this.isFocused = true;
}
}

@action handleFocusOut(_: FocusEvent): void {
this.isFocused = false;
}
}
3 changes: 2 additions & 1 deletion packages/forms/addon/components/form-field/checkbox.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
name={{@name}}
checked={{this.isChecked}}
type="checkbox"
class="form-checkbox {{if @isSmall "form-checkbox-sm" (if @isLarge "form-checkbox-lg")}}"
class="form__checkbox {{if @isSmall "form__checkbox--sm" (if @isLarge "form__checkbox--lg")}}"
data-test-id="form-field-checkbox"
...attributes
>
2 changes: 1 addition & 1 deletion packages/forms/addon/components/form-field/feedback.hbs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div
id={{@id}}
class="form-field-feedback {{if this.isError "is-error"}} {{if @isSmall "form-field-feedback-sm" (if @isLarge "form-field-feedback-lg")}}"
class="form__feedback {{if this.isError "form__feedback--state-error"}} {{if @isSmall "form__feedback--sm" (if @isLarge "form__feedback--lg")}}"
data-test-id="form-field-feedback"
aria-live={{if this.isError "assertive" "polite"}}
...attributes
Expand Down
2 changes: 1 addition & 1 deletion packages/forms/addon/components/form-field/hint.hbs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div
id={{@id}}
class="form-field-hint {{if @isSmall "form-field-hint-sm" (if @isLarge "form-field-hint-lg")}}"
class="form__hint {{if @isSmall "form__hint--sm" (if @isLarge "form__hint--lg")}}"
data-test-id="form-field-hint"
...attributes
>
Expand Down
3 changes: 2 additions & 1 deletion packages/forms/addon/components/form-field/input.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
id={{@id}}
value={{@value}}
type={{this.type}}
class="form-input {{if @isSmall "form-input-sm" (if @isLarge "form-input-lg")}}"
class="form__input {{if @isSmall "form__input--sm" (if @isLarge "form__input--lg")}}"
data-test-id="form-field-input"
...attributes
>
2 changes: 1 addition & 1 deletion packages/forms/addon/components/form-field/label.hbs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<label
for={{@for}}
class="form-field-label {{if @isSmall "form-field-label-sm" (if @isLarge "form-field-label-lg")}}"
class="form__label {{if @isSmall "form__label--sm" (if @isLarge "form__label--lg")}}"
data-test-id="form-field-label"
...attributes
>
Expand Down
3 changes: 2 additions & 1 deletion packages/forms/addon/components/form-field/radio.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
value={{@value}}
checked={{this.isChecked}}
type="radio"
class="form-radio {{if @isSmall "form-radio-sm" (if @isLarge "form-radio-lg")}}"
class="form__radio {{if @isSmall "form__radio--sm" (if @isLarge "form__radio--lg")}}"
data-test-id="form-field-radio"
...attributes
>
3 changes: 2 additions & 1 deletion packages/forms/addon/components/form-field/textarea.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
{{on "change" this.handleOnChange}}
id={{@id}}
value={{@value}}
class="form-textarea {{if @isSmall "form-textarea-sm" (if @isLarge "form-textarea-lg")}}"
class="form__textarea {{if @isSmall "form__textarea--sm" (if @isLarge "form__textarea--lg")}}"
data-test-id="form-field-textarea"
...attributes
>
</textarea>
2 changes: 1 addition & 1 deletion packages/forms/addon/components/form-input.hbs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<FormField
@isSmall={{@isSmall}}
@isLarge={{@isLarge}}
class="form-input-container {{@containerClass}} {{if @isSmall "form-input-container-sm" (if @isLarge "form-input-container-lg")}}"
class="form-input-container {{@containerClass}} {{if @isSmall "form-input-container--sm" (if @isLarge "form-input-container--lg")}}"
as |f|
>
{{#if @label}}
Expand Down
5 changes: 2 additions & 3 deletions packages/forms/addon/components/form-radio-group.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
@isSmall={{@isSmall}}
@isLarge={{@isLarge}}
class="form-radio-group-container
{{if this.showErrorFeedback "has-error"}}
{{if @isInline "is-inline"}} {{@containerClass}}
{{if @isSmall "form-radio-group-container-sm" (if @isLarge "form-radio-group-container-lg")}}"
{{if @isInline "form-radio-group-container--inline"}} {{@containerClass}}
{{if @isSmall "form-radio-group-container--sm" (if @isLarge "form-radio-group-container--lg")}}"
role="radiogroup"
...attributes
as |f|
Expand Down
13 changes: 4 additions & 9 deletions packages/forms/addon/components/form-radio.hbs
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
<FormField
@isSmall={{@isSmall}}
@isLarge={{@isLarge}}
class="form-radio-container {{@containerClass}} {{if @isSmall "form-radio-container-sm" (if @isLarge "form-radio-container-lg")}}"
class="form-radio-container {{@containerClass}} {{if @isSmall "form-radio-container--sm" (if @isLarge "form-radio-container--lg")}}"
as |f|
>
<div class="label-container">
<div class="input-container">
<div class="form-radio-container__label-container">
<div class="form-radio-container__input-container">
{{!-- Zero-width space character, used to align checkbox properly --}}
&#8203;
<f.Radio
{{on "focus" this.handleFocusIn}}
{{on "blur" this.handleFocusOut}}

@onChange={{this.handleChange}}
@value={{@value}}
@checked={{@checked}}
Expand All @@ -22,9 +19,7 @@
/>
</div>

<f.Label
class={{if this.isFocused "is-focused"}}
>
<f.Label>
{{#if hasBlock}}
{{yield}}
{{else}}
Expand Down
13 changes: 0 additions & 13 deletions packages/forms/addon/components/form-radio.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import Component from '@glimmer/component';
import { action } from '@ember/object';
import { tracked } from '@glimmer/tracking';

interface FormRadioArgs {
label?: string;
Expand All @@ -20,8 +19,6 @@ interface FormRadioArgs {
}

export default class FormRadio extends Component<FormRadioArgs> {
@tracked isFocused = false;

@action handleChange(value: unknown, event: Event): void {
event.preventDefault();

Expand All @@ -33,14 +30,4 @@ export default class FormRadio extends Component<FormRadioArgs> {
this.args._parentOnChange(value, event);
}
}

@action handleFocusIn(event: FocusEvent): void {
if (event.relatedTarget !== null) {
this.isFocused = true;
}
}

@action handleFocusOut(_: FocusEvent): void {
this.isFocused = false;
}
}
2 changes: 1 addition & 1 deletion packages/forms/addon/components/form-select.hbs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<FormField
@isSmall={{@isSmall}}
@isLarge={{@isLarge}}
class="form-select-container {{@containerClass}} {{if @isSmall "form-select-container-sm" (if @isLarge "form-select-container-lg")}}"
class="form-select-container {{@containerClass}} {{if @isSmall "form-select-container--sm" (if @isLarge "form-select-container--lg")}}"
as |f|
>

Expand Down
2 changes: 1 addition & 1 deletion packages/forms/addon/components/form-textarea.hbs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<FormField
@isSmall={{@isSmall}}
@isLarge={{@isLarge}}
class="form-textarea-container {{@containerClass}} {{if @isSmall "form-textarea-container-sm" (if @isLarge "form-textarea-container-lg")}}"
class="form-textarea-container {{@containerClass}} {{if @isSmall "form-textarea-container--sm" (if @isLarge "form-textarea-container--lg")}}"
as |f|
>
{{#if @label}}
Expand Down
Loading