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

Fix incompatibilities between some AuModal arguments #479

Merged
merged 2 commits into from
Mar 12, 2024
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
9 changes: 5 additions & 4 deletions addon/components/au-modal.gjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { on } from '@ember/modifier';
import { action } from '@ember/object';
import Component from '@glimmer/component';
import { focusTrap } from 'ember-focus-trap';
import { cn } from '../private/helpers/class-names';

// TODO: replace these with the named imports from ember-truth-helpers v4 once our dependencies support that version
import not from 'ember-truth-helpers/helpers/not';
Expand Down Expand Up @@ -33,7 +34,7 @@ export default class AuModal extends Component {
}

get padding() {
if (this.args.padding === 'none') return ' au-c-modal--flush';
if (this.args.padding === 'none') return 'au-c-modal--flush';
else return '';
}

Expand Down Expand Up @@ -89,12 +90,12 @@ export default class AuModal extends Component {
<div class="au-c-modal-backdrop {{if @modalOpen 'is-visible'}}"></div>
<div
id="{{@id}}"
class={{concat
"au-c-modal "
class={{cn
"au-c-modal"
this.size
this.padding
this.overflow
(if @modalOpen " is-visible")
(if @modalOpen "is-visible")
}}
role="dialog"
aria-describedby={{concat "au-c-modal-title-" @id}}
Expand Down
6 changes: 6 additions & 0 deletions addon/private/helpers/class-names.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/**
* A very basic alternative to https://github.com/JedWatson/classnames
*/
export function cn(...classNames: Array<string | undefined>) {
return classNames.filter(Boolean).join(' ');
}
39 changes: 39 additions & 0 deletions tests/integration/private/helpers/class-names-test.gts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { settled, render } from '@ember/test-helpers';
import { tracked } from '@glimmer/tracking';
import { setupRenderingTest } from 'ember-qunit';
import { module, test } from 'qunit';
import { cn } from '@appuniversum/ember-appuniversum/private/helpers/class-names';

module('Integration | Private Helper | class-names', function (hooks) {
setupRenderingTest(hooks);

test('it accepts a list of classes and adds the needed whitespace', async function (assert) {
await render(
<template>
<div data-test class={{cn "foo" "bar" "baz"}}></div>
</template>,
);

assert.dom('[data-test]').hasClass('foo').hasClass('bar').hasClass('baz');
});

test('it removes falsy values', async function (assert) {
class TestState {
@tracked someFlag: boolean = false;
}

const state = new TestState();
await render(
<template>
<div data-test class={{cn "foo" (if state.someFlag "bar") "baz"}}></div>
</template>,
);

assert.dom('[data-test]').hasClass('foo').hasNoClass('bar').hasClass('baz');

state.someFlag = true;
await settled();

assert.dom('[data-test]').hasClass('foo').hasClass('bar').hasClass('baz');
});
});
Loading