Skip to content

Commit

Permalink
Merge pull request #429 from appuniversum/feat/deprecate-au-input-fea…
Browse files Browse the repository at this point in the history
…tures

Deprecate some `AuInput` features
  • Loading branch information
Windvis authored Sep 14, 2023
2 parents 226d253 + 6617864 commit 95705af
Show file tree
Hide file tree
Showing 6 changed files with 268 additions and 116 deletions.
48 changes: 34 additions & 14 deletions addon/components/au-input.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,23 @@
{{this.inputmaskModifier options=this.inputmaskOptions}}
/>
{{else}}
<Input
@value={{@value}}
@type={{this.type}}
class={{this.classes}}
disabled={{@disabled}}
...attributes
/>
{{#if this.useDeprecatedInput}}
<Input
@value={{@value}}
@type={{this.type}}
class={{this.classes}}
disabled={{@disabled}}
...attributes
/>
{{else}}
<input
type={{this.type}}
value={{@value}}
class={{this.classes}}
disabled={{@disabled}}
...attributes
/>
{{/if}}
{{/if}}
{{#if (eq @iconAlignment "right")}}
<AuIcon @icon={{@icon}} @alignment="right" />
Expand All @@ -37,12 +47,22 @@
{{this.inputmaskModifier options=this.inputmaskOptions}}
/>
{{else}}
<Input
@value={{@value}}
@type={{this.type}}
class={{this.classes}}
disabled={{@disabled}}
...attributes
/>
{{#if this.useDeprecatedInput}}
<Input
@value={{@value}}
@type={{this.type}}
class={{this.classes}}
disabled={{@disabled}}
...attributes
/>
{{else}}
<input
type={{this.type}}
value={{@value}}
class={{this.classes}}
disabled={{@disabled}}
...attributes
/>
{{/if}}
{{/if}}
{{/if}}
44 changes: 43 additions & 1 deletion addon/components/au-input.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { action } from '@ember/object';
import Component from '@glimmer/component';
import { assert } from '@ember/debug';
import { assert, deprecate } from '@ember/debug';
import auInputmask from '@appuniversum/ember-appuniversum/modifiers/au-inputmask';

export default class AuInput extends Component {
Expand All @@ -12,6 +12,23 @@ export default class AuInput extends Component {
!this.args.onChange ||
(typeof this.args.onChange === 'function' && this.isMasked),
);

deprecate(
'[AuInput] The `@value` argument is deprecated. Use the `value` attribute and the `{{on}}` modifier instead.',
!('value' in this.args),
{
id: '@appuniversum/ember-appuniversum.au-input',
until: '3.0.0',
for: '@appuniversum/ember-appuniversum',
since: {
enabled: '2.13.0',
},
},
);
}

get useDeprecatedInput() {
return 'value' in this.args || 'type' in this.args;
}

get width() {
Expand Down Expand Up @@ -41,6 +58,18 @@ export default class AuInput extends Component {
}

get type() {
deprecate(
'[AuInput] The `@type` argument is deprecated. Use the `type` attribute instead.',
!('type' in this.args),
{
id: '@appuniversum/ember-appuniversum.au-input',
until: '3.0.0',
for: '@appuniversum/ember-appuniversum',
since: {
enabled: '2.13.0',
},
},
);
return this.args.type || 'text';
}

Expand Down Expand Up @@ -70,6 +99,19 @@ export default class AuInput extends Component {
return {};
}

deprecate(
'[AuInput] The masking feature is deprecated. Use the `{{au-inputmask}}` modifier instead.',
false,
{
id: '@appuniversum/ember-appuniversum.au-input',
until: '3.0.0',
for: '@appuniversum/ember-appuniversum',
since: {
enabled: '2.13.0',
},
},
);

let { mask, maskPlaceholder, maskOptions = {} } = this.args;

let options = {
Expand Down
100 changes: 0 additions & 100 deletions stories/5-components/Forms/AuInput.stories.js

This file was deleted.

62 changes: 62 additions & 0 deletions stories/5-components/Forms/Input/AuInput.stories.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import { hbs } from 'ember-cli-htmlbars';
import { icons } from '../../../assets/icons';

export default {
title: 'Components/Forms/Input/AuInput',
argTypes: {
error: { control: 'boolean', description: 'Add an error state' },
warning: { control: 'boolean', description: 'Add an warning state' },
disabled: {
control: 'boolean',
description: 'Adds a disabled state to the input',
},
width: {
control: 'select',
options: ['default', 'block'],
description: 'Display the input as a block element',
},
icon: {
control: 'select',
options: icons,
description:
'Adds an icon (using an icon implies the use @width="block")',
},
iconAlignment: {
control: 'select',
options: ['left', 'right'],
description: 'Choose the position of the icon',
},
value: {
control: 'text',
},
},
parameters: {
layout: 'padded',
},
};

const Template = (args) => ({
template: hbs`
<AuLabel for="input">Input</AuLabel>
<AuInput
@error={{this.error}}
@warning={{this.warning}}
@disabled={{this.disabled}}
@width={{this.width}}
@icon={{this.icon}}
@iconAlignment={{this.iconAlignment}}
value={{this.value}}
id="input"
/>`,
context: args,
});

export const Component = Template.bind({});
Component.args = {
error: false,
warning: false,
disabled: false,
width: '',
icon: '',
iconAlignment: 'left',
};
45 changes: 45 additions & 0 deletions stories/5-components/Forms/Input/Inputmask.stories.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { hbs } from 'ember-cli-htmlbars';

export default {
title: 'Components/Forms/Input/Inputmasking',
argTypes: {
value: {
control: 'text',
},
mask: {
control: 'text',
},
placeholder: {
control: 'text',
},
},
parameters: {
layout: 'padded',
},
};

const Template = (args) => ({
template: hbs`
<AuContent class="au-u-max-width-small">
<p>
You can add input masking to the AuInput by applying the <AuPill>{{"{{au-inputmask}}"}}</AuPill> modifier. It is a simple wrapper around the inputmask library. Usage instructions can be found in the <AuLinkExternal href="https://github.com/RobinHerbots/Inputmask">inputmask repo</AuLinkExternal>.
</p>
</AuContent>
<br>
<AuLabel for="masked-input">Masked input</AuLabel>
<AuInput
id="masked-input"
value={{this.value}}
{{au-inputmask options=(hash
mask=this.mask
placeholder=this.placeholder
)}}
/>`,
context: args,
});

export const Component = Template.bind({});
Component.args = {
mask: '99.99.99-999.99',
placeholder: '_',
};
Loading

0 comments on commit 95705af

Please sign in to comment.