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

refactor: the 'base' and a few 'header' components #6

Merged
merged 2 commits into from
May 21, 2024
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
52 changes: 21 additions & 31 deletions src/components/base/BaseButton.vue
Original file line number Diff line number Diff line change
@@ -1,37 +1,27 @@
<script setup>
<script setup lang="ts">
import { watch } from 'vue';
import BaseIcon from '@/components/base/BaseIcon.vue';

const props = defineProps({
text: {
type: String,
default: '',
},
display: {
type: String,
default: 'filled',
},
size: {
type: String,
default: 'normal',
},
icon: {
type: String,
default: null,
},
iconPosition: {
type: String,
default: 'left',
},
rounded: {
type: Boolean,
default: null,
},
disabled: {
type: Boolean,
default: false,
},
});
export interface Props {
text: string,
display: string,
size: string,
icon: string | null,
iconPosition: string | null,
rounded: boolean | null,
disabled: boolean,
}

const props = withDefaults(defineProps<Props>(), {
text: '',
display: 'filled',
size: 'normal',
icon: null,
iconPosition: 'left',
rounded: null,
disabled: false
})


let _icon;
watch(() => props.icon, (value) => _icon = value, { immediate: true });
Expand Down
4 changes: 3 additions & 1 deletion src/components/base/BaseCheckbox.vue
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ const pt = {
}
}

function getAriaChecked() {
type AriaChecked = 'mixed' | 'true' | 'false'

function getAriaChecked(): AriaChecked {
if (props.modelValue === null) return 'mixed';
if (props.modelValue === true) return 'true';
else return 'false';
Expand Down
8 changes: 6 additions & 2 deletions src/components/base/BaseIcon.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
<script setup>
<script setup lang="ts">
import { getIcon } from '@/utils/icons';

const props = defineProps(['name']);
export interface Props {
name: string
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should I set the type of the name to be part of a list of names, or just let it string ?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

string should be enough

}

const props = defineProps<Props>()
</script>

<template>
Expand Down
27 changes: 14 additions & 13 deletions src/components/header/GlobalHeader.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,28 @@
</div>
</template>

<script setup>
<script setup lang="ts">
import { computed } from 'vue';
import { useStore } from 'vuex';
import Navbar from '@/components/header/Navbar.vue';
import TitleBar from '@/components/header/TitleBar.vue';
import PanelsToggle from '@/components/header/PanelsToggle.vue';
import Tools from '@/components/header/Tools.vue';

const props = defineProps({
configErrorTitle: {
type: String,
default: () => '',
},
});

const store = useStore();
export interface Props {
configErrorTitle: string
}

const props = withDefaults(defineProps<Props>(), {
configErrorTitle: ''
})

const show = computed(() => config.value?.header?.show);
const manifests = computed(() => store.getters['contents/manifests']);
const store = useStore();
const config = computed(() => store.getters['config/config']);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it necessary to create an interface and assign it as a type to 'config' ?

const item = computed(() => store.getters['contents/item']);
const showNavbar = computed(() => config.value?.header?.navigation || true);
const showPanelsToggle = computed(() => (config.value?.header?.panelsToggle !== undefined ? config.value?.header?.panelsToggle : true));
const show = computed<boolean | undefined>(() => config.value?.header?.show);
const manifests = computed<Manifest[]>(() => store.getters['contents/manifests']);
const item = computed<Item>(() => store.getters['contents/item']);
const showNavbar = computed<boolean>(() => config.value?.header?.navigation || true);
const showPanelsToggle = computed<boolean | undefined>(() => (config.value?.header?.panelsToggle !== undefined ? config.value?.header?.panelsToggle : true));
</script>
21 changes: 13 additions & 8 deletions src/components/header/Language.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,37 +17,42 @@
</div>
</template>

<script setup>
<script setup lang="ts">
import {
computed, onMounted, ref, watch,
} from 'vue';
import { useStore } from 'vuex';
import { useI18n } from 'vue-i18n';
import BaseDropdown from '@/components/base/BaseDropdown.vue';

interface Language {
label: string,
value: string
}

const store = useStore();
const { locale: i18nLocale } = useI18n();

const langs = ref([
const langs = ref<Language[]>([
{ label: 'DE', value: 'de-de' },
{ label: 'EN', value: 'en-US' },
]);
const selectedLang = ref(langs.value[0]);
const showDropdown = ref(false);
const selectedLang = ref<Language>(langs.value[0]);
const showDropdown = ref<boolean>(false);
const config = computed(() => store.getters['config/config']);

watch(
selectedLang,
(lang) => {
i18nLocale.value = lang;
i18nLocale.value = lang.value;
},
);

onMounted(() => {
selectedLang.value = config.value.lang || 'en-US';
});

function handleLanguageChange(lang) {
selectedLang.value = lang.value;
function handleLanguageChange(lang: Language) {
selectedLang.value = lang;
}
</script>
</script>