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

[Component] Search #34

Closed
wants to merge 23 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
c3e1978
feat(components): basic css
Jul 13, 2022
6722694
feat(components): add all stories
Jul 13, 2022
900516b
feat(components): add tests
Jul 13, 2022
bdc4816
feat(components): remove unused variables
Jul 13, 2022
d2a5a1a
feat(components): fix test
Jul 13, 2022
b45253b
feat(components): test fix build
Jul 15, 2022
ba4fec0
feat(components): test fix build
Jul 15, 2022
7f0e1d6
feat(components): remove deep scss
Jul 15, 2022
207ccdc
feat(components): remove scoped css
Jul 15, 2022
9018330
feat(components): display cancel icon if value in input
Jul 20, 2022
709c8bf
feat(components): remove forgotten console log
Jul 20, 2022
7cd9664
feat(components): change rounded stories
Jul 20, 2022
578c6e4
feat: search placeholder translation
Jul 25, 2022
e6a0554
fix: review
Jul 27, 2022
2b381ac
Update packages/components/search/stories/search.stories.ts
elisegriset92 Sep 19, 2022
582400c
Update packages/components/search/stories/search.stories.ts
elisegriset92 Sep 19, 2022
8770844
Update packages/components/search/stories/search.stories.ts
elisegriset92 Sep 19, 2022
ce807eb
Update packages/components/search/stories/search.stories.ts
elisegriset92 Sep 19, 2022
db899ef
Update packages/components/search/stories/search.stories.ts
elisegriset92 Sep 19, 2022
fe37dd4
Update packages/components/search/stories/search.stories.ts
elisegriset92 Sep 19, 2022
e47ba5d
Update packages/components/search/stories/search.stories.ts
elisegriset92 Sep 19, 2022
006a5d7
Update packages/components/search/stories/search.stories.ts
elisegriset92 Sep 19, 2022
ba07960
refactor: refacto
Sep 19, 2022
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
1 change: 1 addition & 0 deletions packages/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ export * from './card'
export * from './select'
export * from './icon'
export * from './progress-bar'
export * from './search'
8 changes: 8 additions & 0 deletions packages/components/search/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { withInstall } from '@puik/utils'

import Search from './src/search.vue'

export const PuikSearch = withInstall(Search)
export default PuikSearch

export * from './src/search'
50 changes: 50 additions & 0 deletions packages/components/search/src/search.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { buildProps } from '@puik/utils'
import { useLocale } from '@puik/hooks'
import type { ExtractPropTypes } from 'vue'
import type Search from './search.vue'
const { t } = useLocale()

export const searchProps = buildProps({
modelValue: {
type: [String, Number],
required: false,
default: '',
},
id: {
type: String,
required: false,
default: undefined,
},
placeholder: {
type: String,
required: false,
default: t('puik.search.placeholder'),
},
disabled: {
type: Boolean,
required: false,
default: false,
},
name: {
type: String,
required: false,
default: undefined,
},
autocomplete: {
type: String,
required: false,
default: '',
},
rounded: {
type: Boolean,
required: false,
default: false,
},
} as const)

export type SearchProps = ExtractPropTypes<typeof searchProps>

export const searchEmits = ['update:modelValue']
export type SearchEmits = typeof searchEmits

export type SearchInstance = InstanceType<typeof Search>
72 changes: 72 additions & 0 deletions packages/components/search/src/search.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<template>
<div class="puik-search">
<div class="puik-search__wrapper" :class="searchClasses">
<span class="puik-search__icon puik-h2">search</span>
<input
:id="id"
v-model="value"
class="puik-search__field"
:placeholder="placeholder"
:disabled="disabled"
:autocomplete="autocomplete"
:name="name"
@focus="handleFocus"
@blur="handleBlur"
ga-devfront marked this conversation as resolved.
Show resolved Hide resolved
@keyup.enter="sendContent"
/>
<button
v-if="!disabled && value"
class="puik-search__cancel-icon puik-h2"
@click="deleteContent"
>
cancel
</button>
<div v-if="!autocomplete && !disabled" class="flex">
<puik-button
class="puik-search__confirm-icon"
size="sm"
variant="primary"
@click="sendContent"
>east</puik-button
>
</div>
</div>
</div>
</template>
<script setup lang="ts">
import { computed, ref } from 'vue'
import PuikButton from '../../button/src/button.vue'
import { searchEmits, searchProps } from './search'
defineOptions({
name: 'PuikSearch',
})
const props = defineProps(searchProps)
const emit = defineEmits(searchEmits)
const isFocus = ref(false)

const searchClasses = computed(() => ({
'puik-search__wrapper--focus': isFocus.value,
'puik-search__wrapper--disabled': props.disabled,
'puik-search__wrapper--rounded-input': props.rounded,
}))

const handleFocus = () => (isFocus.value = true)
const handleBlur = () => (isFocus.value = false)

const deleteContent = () => {
emit('update:modelValue', null)
}

const sendContent = () => {
emit('update:modelValue', value.value)
}

const value = computed<string | number>({
get() {
return props.modelValue
},
set(item) {
emit('update:modelValue', item)
},
})
</script>
Loading