Skip to content
This repository has been archived by the owner on Aug 2, 2024. It is now read-only.

Add support for disabled and loading states to polaris-setting-toggle #199

Merged
Merged
Show file tree
Hide file tree
Changes from 2 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
9 changes: 6 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
# ember-polaris Changelog

### v.1.7.7 (october 8, 2018)
### Unreleased
- [199](https://github.com/smile-io/ember-polaris/pull/199) [ENHANCEMENT] Add support for disabled and loading states to `polaris-setting-toggle`.

### v.1.7.7 (October 8, 2018)
- [189](https://github.com/smile-io/ember-polaris/pull/189) [FIX] Detect length of decimal places in number as per expectations.

### v.1.7.6 (october 5, 2018)
### v.1.7.6 (October 5, 2018)
- [#181](https://github.com/smile-io/ember-polaris/pull/181) [internal] autofix code to use our latest eslint rules.

### v.1.7.5 (october 4, 2018)
### v.1.7.5 (October 4, 2018)
- [#173](https://github.com/smile-io/ember-polaris/pull/173) [internal] setup eslint, prettier & ember-template-lint.

### v.1.7.4 (September 17, 2018)
Expand Down
2 changes: 2 additions & 0 deletions addon/templates/components/polaris-setting-toggle.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
{{#if action}}
{{polaris-button
text=action.text
disabled=action.disabled
loading=action.loading
primary=enabled
onClick=(action "fireAction" action)
}}
Expand Down
6 changes: 5 additions & 1 deletion docs/setting-toggle.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Inline usage:
enabled=enabled
action=(hash
text="Toggle it!"
loading=isToggleSettingRunning
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we document disabled too?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thought about it but I'm not sure there's any real value

onAction=(action "toggleSetting")
)
}}
Expand All @@ -29,6 +30,9 @@ Block usage:
onAction=(action (mut enabled) false)
)
}}
This setting is currently <strong>{{if enabled "enabled" "disabled"}}</strong>
This setting is currently
{{polaris-text-style variation="strong"}}
{{if enabled "enabled" "disabled"}}
{{/polaris-text-style}}
{{/polaris-setting-toggle}}
```
40 changes: 39 additions & 1 deletion tests/integration/components/polaris-setting-toggle-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ test('it handles the enabled attribute correctly', function(assert) {
);
});

test('it handles the suppied action correctly', function(assert) {
test('it handles the supplied action correctly', function(assert) {
this.set('actionFired', false);
this.render(hbs`
{{polaris-setting-toggle
Expand All @@ -160,3 +160,41 @@ test('it handles the suppied action correctly', function(assert) {
click(settingActionButtonSelector);
assert.ok(this.get('actionFired'), 'fires the action when button clicked');
});

test("it obeys the passed-in action hash's loading and disabled flags", function(assert) {
this.setProperties({
isLoading: true,
isDisabled: false,
});

this.render(hbs`
{{polaris-setting-toggle
action=(hash
text="Toggle"
loading=isLoading
disabled=isDisabled
onAction=(action (mut dummy))
)
}}
`);

let button = find(settingActionButtonSelector);
assert.ok(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this could also be written as

assert.dom(settingActionButtonSelector).hasClass('Polaris-Button--loading', 'button is in loading state when loading is true');

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It could... but I want to get this out quickly so wasn't going to update the test file to use the newer things 🤷‍♂️

button.classList.contains('Polaris-Button--loading'),
'button is in loading state when loading is true'
);

this.setProperties({
isLoading: false,
isDisabled: true,
});

assert.ok(
button.classList.contains('Polaris-Button--disabled'),
'button is in disabled state when disabled is true'
);
assert.notOk(
button.classList.contains('Polaris-Button--loading'),
'button is not in loading state when loading is false'
);
});