Skip to content

Commit

Permalink
feat(mox:typeahead): add light mode to mox/t-ahead component
Browse files Browse the repository at this point in the history
  • Loading branch information
jayjayjpg committed Jul 25, 2023
1 parent 2047570 commit ce14d30
Show file tree
Hide file tree
Showing 5 changed files with 286 additions and 121 deletions.
36 changes: 19 additions & 17 deletions addon/components/mox/input.hbs
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
{{#if @label}}
<Mox::Label for={{@id}} @isRequired={{@isRequired}}>{{@label}}</Mox::Label>
{{/if}}
<input
id={{@id}}
type="text"
class="px-4 py-2 w-full text-gray-800 dark:text-white text-sm rounded bg-white dark:bg-gray-800
read-only:text-gray-800 dark:read-only:text-white disabled:text-gray-600 dark:disabled:text-gray-500
disabled:bg-gray-200 read-only:bg-gray-50 disabled:border-gray-200 read-only:border-gray-400
dark:disabled:bg-gray-700 dark:read-only:bg-gray-700 dark:disabled:border-gray-700 dark:read-only:border-gray-700 disabled:cursor-not-allowed
read-only:focus:border-cyan-500 dark:read-only:focus:border-white dark:ready-only:focus:ring-white
{{if this.isValid 'border-gray-400 dark:border-gray-500 focus:border-cyan-500 focus:ring-cyan-500'
'border-red-500 dark:border-red-800 active:border-red-500 dark:active:border-red-900 focus:border-red-500 dark:focus:border-red-900 focus:ring-red-500 dark:focus:ring-red-900'}}"
value={{@value}}
placeholder={{@placeholder}}
aria-invalid={{not this.isValid}} {{on "input" this.onInput}}
data-test-mox-input
...attributes
/>
<Mox::FormError @error={{@error}} id={{concat @id "-error-message"}} data-test-mox-input-error />
<div class="flex flex-col">
<input
id={{@id}}
type="text"
class="px-4 py-2 w-full text-gray-800 dark:text-white text-sm rounded bg-white dark:bg-gray-800
read-only:text-gray-800 dark:read-only:text-white disabled:text-gray-600 dark:disabled:text-gray-500
disabled:bg-gray-200 read-only:bg-gray-50 disabled:border-gray-200 read-only:border-gray-400
dark:disabled:bg-gray-700 dark:read-only:bg-gray-700 dark:disabled:border-gray-700 dark:read-only:border-gray-700 disabled:cursor-not-allowed
read-only:focus:border-cyan-500 dark:read-only:focus:border-white dark:ready-only:focus:ring-white
{{if this.isValid 'border-gray-400 dark:border-gray-500 focus:border-cyan-500 focus:ring-cyan-500'
'border-red-500 dark:border-red-800 active:border-red-500 dark:active:border-red-900 focus:border-red-500 dark:focus:border-red-900 focus:ring-red-500 dark:focus:ring-red-900'}}"
value={{@value}}
placeholder={{@placeholder}}
aria-invalid={{not this.isValid}} {{on "input" this.onInput}}
data-test-mox-input
...attributes
/>
<Mox::FormError @error={{@error}} id={{concat @id "-error-message"}} data-test-mox-input-error />
</div>
10 changes: 5 additions & 5 deletions addon/components/mox/typeahead-select.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
/>
<span class="ml-3 absolute right-0 flex items-center pr-2 pointer-events-none">
<svg
class="h-5 w-5 text-gray-400"
class="h-5 w-5 text-gray-600 dark:text-gray-400"
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 20 20"
fill="currentColor"
Expand All @@ -43,7 +43,7 @@
</div>

<div
class="absolute mt-1 w-full rounded-md bg-gray-800 z-10
class="absolute mt-1 w-full rounded-md bg-gray-50 dark:bg-gray-800 z-10
{{if (or (not this.isShowingMatches) (eq this.matches.length 0)) "hidden"}}"
data-test-typeahead-matches
>
Expand All @@ -52,21 +52,21 @@
id={{concat "typeaheadselectlistbox" @id}}
tabindex="1"
role="listbox"
class="max-h-56 rounded-md text-base overflow-auto focus:outline-none sm:text-sm border border-gray-500"
class="max-h-56 rounded-md text-base overflow-auto focus:outline-none sm:text-sm border border-gray-300 dark:border-gray-500"
>
{{!-- template-lint-enable no-positive-tabindex --}}
{{#each this.matches as |match idx|}}
{{!-- template-lint-disable require-presentational-children --}}
<li
id={{concat "listbox-item-" idx}}
role="option"
class="text-white cursor-default select-none relative hover:bg-gray-700
class="text-white cursor-default select-none relative hover:bg-gray-200 dark:hover:bg-gray-700
{{if
(eq
(get match this.optionValueKey)
(get this.internalSelectedOption this.optionValueKey)
)
"bg-gray-700"
"bg-gray-200 dark:bg-gray-700"
}}"
data-test-select-option
aria-selected={{eq
Expand Down
129 changes: 129 additions & 0 deletions stories/mox-typeahead-select-light.stories.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
import { hbs } from 'ember-cli-htmlbars';
import { action } from '@ember/object';

const options = [
{ name: 'Apple', value: 'apple' },
{ name: 'Banana', value: 'banana' },
{ name: 'Carrot', value: 'carrot' },
];

export default {
title: 'Mox Light/Mox::TypeaheadSelect',
argTypes: {
options: { control: 'text' },
buttonType: { control: 'text' },
},
parameters: {
backgrounds: {
default: 'Mute',
values: [
{
name: 'White',
value: '#ffffff',
},
{
name: 'Mute',
value: '#F3F4F6',
},
],
},
},
};

const Template = (args) => ({
template: hbs`
<div class={{this.wrapperClass}}>
<Mox::TypeaheadSelect
@options={{this.connectorTypes}}
@selectedOption={{this.selectedConnectorType}}
@onChange={{this.setConnectorType}}
@isDisabled={{this.isEditing}}
@label={{this.label}}
@id={{this.id}}
@isValid={{this.isValid}}
@error={{this.error}}
/>
</div>
`,
context: args,
});

const LabelledTemplate = (args) => ({
template: hbs`
<Mox::Label for={{this.id}}>Food</Mox::Label>
<div class={{this.wrapperClass}}>
<Mox::TypeaheadSelect
@options={{this.connectorTypes}}
@selectedOption={{this.selectedConnectorType}}
@onChange={{this.setConnectorType}}
@isDisabled={{this.isEditing}}
@id={{this.id}}
/>
</div>
`,
context: args,
});

export const Default = Template.bind({});
Default.args = {
connectorTypes: options,
selectedConnectorType: options[0],
isEditing: false,
setConnectorType: action(function (value) {
this.set('selectedConnectorType', value);
}),
wrapperClass: null,
label: 'Fruit',
id: 'fruit-basket',
};

export const Short = Template.bind({});
Short.args = {
connectorTypes: options,
selectedConnectorType: options[0],
isEditing: false,
setConnectorType: action(function (value) {
this.set('selectedConnectorType', value);
}),
wrapperClass: 'w-20',
label: 'Fruit',
id: 'fruit-basket',
};

export const ExternalLabel = LabelledTemplate.bind({});
ExternalLabel.args = {
connectorTypes: options,
selectedConnectorType: options[0],
isEditing: false,
setConnectorType: action(function (value) {
this.set('selectedConnectorType', value);
}),
wrapperClass: null,
id: 'fruit-basket',
};

export const Disabled = Template.bind({});
Disabled.args = {
connectorTypes: options,
selectedConnectorType: options[0],
isEditing: true,
setConnectorType: action(function (value) {
this.set('selectedConnectorType', value);
}),
label: 'Fruit',
id: 'fruit-basket',
};

export const Errors = Template.bind({});
Errors.args = {
connectorTypes: options,
selectedConnectorType: options[0],
isEditing: true,
setConnectorType: action(function (value) {
this.set('selectedConnectorType', value);
}),
label: 'Fruit',
id: 'fruit-basket',
isValid: false,
error: 'No more fruit',
};
38 changes: 26 additions & 12 deletions stories/mox-typeahead-select.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,16 @@ export default {
parameters: {
backgrounds: {
default: 'Dark',
values: [
{
name: 'Dark',
value: '#111827',
},
{
name: 'Sky',
value: '#06B6D4',
},
],
},
},
};
Expand All @@ -40,15 +50,17 @@ const Template = (args) => ({

const LabelledTemplate = (args) => ({
template: hbs`
<Mox::Label for={{this.id}}>Food</Mox::Label>
<div class={{this.wrapperClass}}>
<Mox::TypeaheadSelect
@options={{this.connectorTypes}}
@selectedOption={{this.selectedConnectorType}}
@onChange={{this.setConnectorType}}
@isDisabled={{this.isEditing}}
@id={{this.id}}
/>
<div class="dark">
<Mox::Label for={{this.id}}>Food</Mox::Label>
<div class={{this.wrapperClass}}>
<Mox::TypeaheadSelect
@options={{this.connectorTypes}}
@selectedOption={{this.selectedConnectorType}}
@onChange={{this.setConnectorType}}
@isDisabled={{this.isEditing}}
@id={{this.id}}
/>
</div>
</div>
`,
context: args,
Expand All @@ -62,7 +74,7 @@ Default.args = {
setConnectorType: action(function (value) {
this.set('selectedConnectorType', value);
}),
wrapperClass: null,
wrapperClass: 'dark',
label: 'Fruit',
id: 'fruit-basket',
};
Expand All @@ -75,7 +87,7 @@ Short.args = {
setConnectorType: action(function (value) {
this.set('selectedConnectorType', value);
}),
wrapperClass: 'w-20',
wrapperClass: 'dark w-20',
label: 'Fruit',
id: 'fruit-basket',
};
Expand All @@ -88,7 +100,7 @@ ExternalLabel.args = {
setConnectorType: action(function (value) {
this.set('selectedConnectorType', value);
}),
wrapperClass: null,
wrapperClass: 'dark',
id: 'fruit-basket',
};

Expand All @@ -102,6 +114,7 @@ Disabled.args = {
}),
label: 'Fruit',
id: 'fruit-basket',
wrapperClass: 'dark',
};

export const Errors = Template.bind({});
Expand All @@ -116,4 +129,5 @@ Errors.args = {
id: 'fruit-basket',
isValid: false,
error: 'No more fruit',
wrapperClass: 'dark',
};
Loading

0 comments on commit ce14d30

Please sign in to comment.