-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
main point is to have an input specialized in search
- Loading branch information
Showing
8 changed files
with
195 additions
and
2 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
54 changes: 54 additions & 0 deletions
54
doc-app/tests/integration/components/ember-input/prefabs/tpk-search-test.gts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { module, test } from 'qunit'; | ||
import { setupRenderingTest } from 'ember-qunit'; | ||
import { render, triggerEvent, waitFor } from '@ember/test-helpers'; | ||
import { setupIntl } from 'ember-intl/test-support'; | ||
import TpkSearch from '@triptyk/ember-input/components/prefabs/tpk-search'; | ||
import tpkSearchPage from '../../../../pages/tpk-search'; | ||
import { a11yAudit } from 'ember-a11y-testing/test-support'; | ||
|
||
|
||
module( | ||
'Integration | Component | Prefabs | tpk-search', | ||
function (hooks) { | ||
setupRenderingTest(hooks); | ||
setupIntl(hooks, 'fr-fr'); | ||
|
||
async function renderComponent(assert: Assert) { | ||
const mockSearch = () => { | ||
return new Promise((res) => { | ||
assert.step('search'); | ||
setTimeout(() => { | ||
res(null); | ||
}, 500); | ||
}); | ||
}; | ||
|
||
await render( | ||
<template> | ||
<TpkSearch | ||
@label="label" | ||
@placeholder="Narrow the stack" | ||
@onSearch={{mockSearch}} | ||
/> | ||
</template> | ||
); | ||
} | ||
|
||
test('render search icon by default. Switch to loader icon when onSearch is running', async function (assert) { | ||
await renderComponent(assert); | ||
await tpkSearchPage.input('search'); | ||
triggerEvent('form', 'submit') | ||
await waitFor('.tpk-search-loader'); | ||
assert.dom('.tpk-search-loader').exists(); | ||
await waitFor('[data-test-tpk-search-icon]'); | ||
assert.dom('[data-test-tpk-search-icon]').exists(); | ||
assert.verifySteps(['search']); | ||
}); | ||
|
||
test('Accessibility', async function (assert) { | ||
assert.expect(0); | ||
await renderComponent(assert); | ||
await a11yAudit(); | ||
}); | ||
}, | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { | ||
clickable, | ||
create, | ||
fillable, | ||
focusable, | ||
triggerable, | ||
} from 'ember-cli-page-object'; | ||
|
||
export default create({ | ||
scope: '.tpk-search', | ||
input: fillable('.tpk-search-input'), | ||
focus: focusable('.tpk-search-input'), | ||
button: create({ | ||
scope: '.tpk-search-button', | ||
click: clickable(), | ||
enter: triggerable('keydown', undefined, { | ||
eventProperties: { key: 'Enter' }, | ||
}), | ||
}), | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
@import url('./components/prefabs/tpk-toggle.css'); | ||
@import url('./components/prefabs/tpk-search.css'); | ||
@import url('./components/prefabs/tpk-prefab-button.css'); |
50 changes: 50 additions & 0 deletions
50
packages/ember-input/src/components/prefabs/tpk-search.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
.tpk-search-label { | ||
@apply flex items-center input; | ||
} | ||
|
||
.tpk-search-input { | ||
@apply w-full; | ||
} | ||
|
||
.tpk-search-icon { | ||
@apply p-1; | ||
} | ||
|
||
.loader { | ||
position: relative; | ||
height: 20px; | ||
width: 20px; | ||
top: 0; | ||
left: 0; | ||
display: inline-block; | ||
animation: around 5.4s infinite; | ||
} | ||
|
||
@keyframes around { | ||
0% { | ||
transform: rotate(0deg) | ||
} | ||
100% { | ||
transform: rotate(360deg) | ||
} | ||
} | ||
|
||
.loader::after, .loader::before { | ||
content: ""; | ||
background: white; | ||
position: absolute; | ||
display: inline-block; | ||
width: 100%; | ||
height: 100%; | ||
border-width: 2px; | ||
border-color: #333 #333 transparent transparent; | ||
border-style: solid; | ||
border-radius: 20px; | ||
box-sizing: border-box; | ||
animation: around 0.7s ease-in-out infinite; | ||
} | ||
|
||
.loader::after { | ||
animation: around 0.7s ease-in-out 0.1s infinite; | ||
background: transparent; | ||
} |
67 changes: 67 additions & 0 deletions
67
packages/ember-input/src/components/prefabs/tpk-search.gts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import type { MergeDeep } from 'type-fest'; | ||
import type { BaseUIComponentArgs } from '../base'; | ||
import Component from '@glimmer/component'; | ||
import { task } from 'ember-concurrency'; | ||
import { on } from '@ember/modifier'; | ||
import TpkInputComponent from '../tpk-input.gts'; | ||
|
||
export type TpkSearchPrefabSignature = { | ||
Args: MergeDeep< | ||
BaseUIComponentArgs['Args'], | ||
{ | ||
placeholder?: string; | ||
label?: string; | ||
onSearch: (value: string, e: Event) => unknown; | ||
} | ||
>; | ||
Blocks: { | ||
default: []; | ||
}; | ||
Element: HTMLDivElement; | ||
}; | ||
|
||
export default class TpkSearchPrefabComponent extends Component<TpkSearchPrefabSignature> { | ||
performSearch = task(this, { drop: true }, async (value: string, e: Event) => { | ||
e.preventDefault(); | ||
return this.args.onSearch(value, e); | ||
}); | ||
|
||
submitSearch = (e: Event) => { | ||
e.preventDefault(); | ||
const value = (e.target as HTMLInputElement).value; | ||
this.performSearch.perform(value, e); | ||
}; | ||
|
||
get labelOrDefault () { | ||
return this.args.label ?? ''; | ||
} | ||
|
||
<template> | ||
<form {{ on 'submit' this.submitSearch }}> | ||
<TpkInputComponent | ||
@label={{this.labelOrDefault}} | ||
@placeholder={{@placeholder}} | ||
@type="search" | ||
as |C|> | ||
<div class="tpk-search" data-test-tpk-prefab-search-container ...attributes> | ||
<C.Label class="tpk-search-label"> | ||
{{#if this.performSearch.isRunning}} | ||
<div class="tpk-search-button"> | ||
<i class="tpk-search-loader"></i> | ||
</div> | ||
{{else}} | ||
<img | ||
src='/assets/icons/search.svg' | ||
data-test-tpk-search-icon | ||
alt='magnyfying glass' | ||
class='tpk-search-button' | ||
/> | ||
{{/if}} | ||
<C.Input class="tpk-search-input" /> | ||
</C.Label> | ||
</div> | ||
</TpkInputComponent> | ||
</form> | ||
</template> | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters