Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

feat: dropdown improvements #45

Merged
merged 1 commit into from
Sep 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
11 changes: 9 additions & 2 deletions src/components/Dropdown/Dropdown.stories.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export const defaultArgs = {
control: {
type: 'boolean',
},
defaultValue: false,
defaultValue: true,
},
positioningDisabled: {
control: {
Expand Down Expand Up @@ -222,5 +222,12 @@ export const WithIcon = (args) => {

<Canvas>
<Story name="Default" argTypes={{ ...Default.argTypes }} args={{}} />
<Story name="With Icon" argTypes={{ ...WithIcon.argTypes }} args={{}} />
</Canvas>

<Canvas>
<Story
name="With Icon"
argTypes={{ ...WithIcon.argTypes }}
args={{ content: '', autoSize: false }}
/>
</Canvas>
16 changes: 11 additions & 5 deletions src/components/Dropdown/Dropdown.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script setup lang="ts">
import List from './List.vue';
import { Dropdown } from 'floating-vue';
import { reactive } from 'vue';
import { reactive, computed } from 'vue';
import 'floating-vue/dist/style.css';
import Button from '../Button/Button.vue';
export interface Props {
Expand Down Expand Up @@ -43,12 +43,13 @@ export interface Props {
multiple?: boolean;
searchable?: boolean;
actions?: boolean;
icon?: string;
}
const props = withDefaults(defineProps<Props>(), {
popperClass: '',
placement: 'auto',
content: 'deneme',
strategy: 'fixed',
content: '',
strategy: 'absolute',
triggers: () => ['click'],
delay: 0,
shown: false,
Expand All @@ -68,6 +69,7 @@ const props = withDefaults(defineProps<Props>(), {
multiple: false,
searchable: true,
actions: true,
icon: '',
});
const emit = defineEmits([
'show',
Expand Down Expand Up @@ -95,6 +97,10 @@ const onResize = () => {
const onSelect = (value: string) => {
emit('select', { value });
};
const iconName = computed(() => {
if (props.icon) return props.icon;
return state.visible ? 'ChevronUpIcon' : 'ChevronDownIcon';
});
</script>
<template>
<div style="display: flex">
Expand All @@ -109,9 +115,9 @@ const onSelect = (value: string) => {
<Button
v-if="!$slots.default"
iconRight
variant="secondary"
:variant="props.content?.length > 0 ? 'secondary' : 'icon'"
iconKind="mini"
:icon="state.visible ? 'ChevronUpIcon' : 'ChevronDownIcon'"
:icon="iconName"
>
{{ props.content }}
</Button>
Expand Down