-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(input): search input example (#439)
- Loading branch information
1 parent
f713fbd
commit e78dc2c
Showing
6 changed files
with
226 additions
and
0 deletions.
There are no files selected for viewing
62 changes: 62 additions & 0 deletions
62
packages/angular-test-app/src/preview-examples/input-search.ts
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,62 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2023 Siemens AG | ||
* | ||
* SPDX-License-Identifier: MIT | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
import { Component } from '@angular/core'; | ||
|
||
@Component({ | ||
selector: 'app-example', | ||
template: ` | ||
<form class="needs-validation m-2"> | ||
<ix-input-group> | ||
<span slot="input-start"> | ||
<ix-icon name="search" size="16"></ix-icon> | ||
</span> | ||
<input | ||
ng-init="verifyStart()" | ||
[(ngModel)]="customSearch" | ||
name="input" | ||
(keyup)="onKey($event)" | ||
id="input-string" | ||
type="string" | ||
class="form-control" | ||
/> | ||
<span slot="input-end"> | ||
<ix-icon-button | ||
(click)="clearInput()" | ||
id="clear-button" | ||
icon="clear" | ||
ghost="{true}" | ||
size="16" | ||
[style.display]="display" | ||
></ix-icon-button> | ||
</span> | ||
</ix-input-group> | ||
</form> | ||
`, | ||
}) | ||
export default class Input { | ||
customSearch = '' | ||
display = 'none' | ||
|
||
public ngOnInit(): void { | ||
if(this.customSearch !== ''){ | ||
this.display = 'block' | ||
} | ||
} | ||
|
||
clearInput() { | ||
this.customSearch = '' | ||
this.display = 'none' | ||
} | ||
|
||
onKey(event: any) { | ||
event.target.value === '' ? this.display = 'none' | ||
: this.display = 'block' | ||
} | ||
} |
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 |
---|---|---|
|
@@ -28,4 +28,8 @@ | |
.group-end { | ||
right: 0px; | ||
} | ||
|
||
::slotted(*) { | ||
display: flex; | ||
} | ||
} |
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
51 changes: 51 additions & 0 deletions
51
packages/html-test-app/src/preview-examples/input-search.html
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,51 @@ | ||
<!-- | ||
SPDX-FileCopyrightText: 2023 Siemens AG | ||
SPDX-License-Identifier: MIT | ||
--> | ||
|
||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>Input Search example</title> | ||
</head> | ||
<body class="theme-brand-dark"> | ||
<form class="needs-validation m-2"> | ||
<ix-input-group> | ||
<span slot="input-start"> | ||
<ix-icon name="search" size="16"></ix-icon> | ||
</span> | ||
<input | ||
onInput="toggleClear()" | ||
id="input-string" | ||
type="string" | ||
class="form-control" | ||
/> | ||
<span slot="input-end"> | ||
<ix-icon-button | ||
id="clear-button" | ||
icon="clear" | ||
ghost="{true}" | ||
size="16" | ||
onClick="{clearInput()}" | ||
></ix-icon-button> | ||
</span> | ||
</ix-input-group> | ||
</form> | ||
<script> | ||
toggleClear(); | ||
function clearInput() { | ||
document.getElementById('input-string').value = ''; | ||
toggleClear(); | ||
} | ||
|
||
function toggleClear() { | ||
const hasContent = document.getElementById('input-string').value !== ''; | ||
document.getElementById('clear-button').style.display = hasContent | ||
? 'block' | ||
: 'none'; | ||
} | ||
</script> | ||
<script type="module" src="./init.js"></script> | ||
</body> | ||
</html> |
54 changes: 54 additions & 0 deletions
54
packages/react-test-app/src/preview-examples/input-search.tsx
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 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2023 Siemens AG | ||
* | ||
* SPDX-License-Identifier: MIT | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
import { IxIcon, IxIconButton, IxInputGroup } from '@siemens/ix-react'; | ||
import React, { useState } from 'react'; | ||
|
||
export default () => { | ||
const [message, setMessage] = useState(''); | ||
|
||
function reset() { | ||
setMessage(''); | ||
} | ||
|
||
let display = message === '' ? 'none' : 'block'; | ||
|
||
const handleChange = (event: { | ||
target: { value: React.SetStateAction<string> }; | ||
}) => { | ||
setMessage(event.target.value); | ||
}; | ||
|
||
return ( | ||
<form className="needs-validation m-2"> | ||
<IxInputGroup> | ||
<span slot="input-start"> | ||
<IxIcon name="search" size="16"></IxIcon> | ||
</span> | ||
<input | ||
id="input-string" | ||
type="string" | ||
className="form-control" | ||
onChange={handleChange} | ||
value={message} | ||
/> | ||
<span slot="input-end"> | ||
<IxIconButton | ||
onClick={reset} | ||
id="clear-button" | ||
icon="clear" | ||
ghost | ||
size="16" | ||
style={{ display: display }} | ||
></IxIconButton> | ||
</span> | ||
</IxInputGroup> | ||
</form> | ||
); | ||
}; |
39 changes: 39 additions & 0 deletions
39
packages/vue-test-app/src/preview-examples/input-search.vue
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,39 @@ | ||
/* * SPDX-FileCopyrightText: 2023 Siemens AG * * SPDX-License-Identifier: MIT * | ||
* This source code is licensed under the MIT license found in the * LICENSE file | ||
in the root directory of this source tree. */ | ||
<script setup lang="ts"> | ||
import { IxIcon, IxIconButton, IxInputGroup } from '@siemens/ix-vue'; | ||
import { ref } from 'vue'; | ||
const text = ref(''); | ||
function clearInput() { | ||
text.value = ''; | ||
} | ||
</script> | ||
|
||
<template> | ||
<form className="needs-validation m-2"> | ||
<IxInputGroup> | ||
<span slot="input-start"> | ||
<IxIcon name="search" size="16"></IxIcon> | ||
</span> | ||
<input | ||
id="input-string" | ||
type="string" | ||
className="form-control" | ||
v-model="text" | ||
/> | ||
<span slot="input-end"> | ||
<IxIconButton | ||
@click="clearInput" | ||
id="clear-button" | ||
icon="clear" | ||
ghost | ||
size="16" | ||
:style="[text === '' ? { display: 'none' } : { display: 'block' }]" | ||
></IxIconButton> | ||
</span> | ||
</IxInputGroup> | ||
</form> | ||
</template> |