build: switch from yarn to npm to manage js dependencies and move js contents to root
yarn v1 is being deprecated and starts to have some issues Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
31
src/components/Address/AddressInfo.story.vue
Normal file
31
src/components/Address/AddressInfo.story.vue
Normal file
@@ -0,0 +1,31 @@
|
||||
<template>
|
||||
<Story>
|
||||
<Variant title="Basic">
|
||||
<AddressInfo :address="address" />
|
||||
</Variant>
|
||||
|
||||
<Variant title="Basic with timezone">
|
||||
<AddressInfo
|
||||
:address="address"
|
||||
:show-timezone="true"
|
||||
:user-timezone="'Europe/Berlin'"
|
||||
/>
|
||||
</Variant>
|
||||
</Story>
|
||||
</template>
|
||||
<script lang="ts" setup>
|
||||
import { IAddress } from "@/types/address.model";
|
||||
import { reactive } from "vue";
|
||||
import AddressInfo from "./AddressInfo.vue";
|
||||
|
||||
const address = reactive<IAddress>({
|
||||
description: "Locaux Motiv",
|
||||
street: "10 Rue Jangot",
|
||||
locality: "Lyon",
|
||||
postalCode: "69007",
|
||||
region: "Auvergne Rhône-Alpes",
|
||||
country: "France",
|
||||
type: "",
|
||||
timezone: "Europe/Dublin",
|
||||
});
|
||||
</script>
|
||||
123
src/components/Address/AddressInfo.vue
Normal file
123
src/components/Address/AddressInfo.vue
Normal file
@@ -0,0 +1,123 @@
|
||||
<template>
|
||||
<address dir="auto">
|
||||
<o-icon
|
||||
v-if="showIcon"
|
||||
:icon="poiInfos?.poiIcon.icon"
|
||||
size="medium"
|
||||
class="icon"
|
||||
/>
|
||||
<p>
|
||||
<span
|
||||
class="addressDescription"
|
||||
:title="poiInfos.name"
|
||||
v-if="poiInfos?.name"
|
||||
>
|
||||
{{ poiInfos.name }}
|
||||
</span>
|
||||
<br v-if="poiInfos?.name" />
|
||||
<span>
|
||||
{{ poiInfos?.alternativeName }}
|
||||
</span>
|
||||
<br />
|
||||
<small
|
||||
v-if="
|
||||
userTimezoneDifferent &&
|
||||
longShortTimezoneNamesDifferent &&
|
||||
timezoneLongNameValid
|
||||
"
|
||||
>
|
||||
🌐
|
||||
{{
|
||||
$t("{timezoneLongName} ({timezoneShortName})", {
|
||||
timezoneLongName,
|
||||
timezoneShortName,
|
||||
})
|
||||
}}
|
||||
</small>
|
||||
<small v-else-if="userTimezoneDifferent" class="">
|
||||
🌐 {{ timezoneShortName }}
|
||||
</small>
|
||||
</p>
|
||||
</address>
|
||||
</template>
|
||||
<script lang="ts" setup>
|
||||
import { addressToPoiInfos, IAddress } from "@/types/address.model";
|
||||
import { computed } from "vue";
|
||||
|
||||
const props = withDefaults(
|
||||
defineProps<{
|
||||
address: IAddress;
|
||||
showIcon?: boolean;
|
||||
showTimezone?: boolean;
|
||||
userTimezone?: string;
|
||||
}>(),
|
||||
{
|
||||
showIcon: false,
|
||||
showTimezone: false,
|
||||
}
|
||||
);
|
||||
|
||||
const poiInfos = computed(() => addressToPoiInfos(props.address));
|
||||
|
||||
const userTimezoneDifferent = computed((): boolean => {
|
||||
return (
|
||||
props.userTimezone != undefined &&
|
||||
props.address.timezone != undefined &&
|
||||
props.userTimezone !== props.address.timezone
|
||||
);
|
||||
});
|
||||
|
||||
const longShortTimezoneNamesDifferent = computed((): boolean => {
|
||||
return (
|
||||
timezoneLongName.value != undefined &&
|
||||
timezoneShortName.value != undefined &&
|
||||
timezoneLongName.value !== timezoneShortName.value
|
||||
);
|
||||
});
|
||||
|
||||
const timezoneLongName = computed((): string | undefined => {
|
||||
return timezoneName("long");
|
||||
});
|
||||
|
||||
const timezoneShortName = computed((): string | undefined => {
|
||||
return timezoneName("short");
|
||||
});
|
||||
|
||||
const timezoneLongNameValid = computed((): boolean => {
|
||||
return (
|
||||
timezoneLongName.value != undefined && !timezoneLongName.value.match(/UTC/)
|
||||
);
|
||||
});
|
||||
|
||||
const timezoneName = (format: "long" | "short"): string | undefined => {
|
||||
return extractTimezone(
|
||||
new Intl.DateTimeFormat(undefined, {
|
||||
timeZoneName: format,
|
||||
timeZone: props.address.timezone,
|
||||
}).formatToParts()
|
||||
);
|
||||
};
|
||||
|
||||
const extractTimezone = (
|
||||
parts: Intl.DateTimeFormatPart[]
|
||||
): string | undefined => {
|
||||
return parts.find((part) => part.type === "timeZoneName")?.value;
|
||||
};
|
||||
</script>
|
||||
<style lang="scss" scoped>
|
||||
@use "@/styles/_mixins" as *;
|
||||
address {
|
||||
font-style: normal;
|
||||
display: flex;
|
||||
justify-content: flex-start;
|
||||
|
||||
span.addressDescription {
|
||||
text-overflow: ellipsis;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
span.icon {
|
||||
@include padding-right(1rem);
|
||||
}
|
||||
}
|
||||
</style>
|
||||
27
src/components/Address/InlineAddress.story.vue
Normal file
27
src/components/Address/InlineAddress.story.vue
Normal file
@@ -0,0 +1,27 @@
|
||||
<template>
|
||||
<Story>
|
||||
<Variant title="with locality">
|
||||
<InlineAddress :physicalAddress="address" />
|
||||
</Variant>
|
||||
|
||||
<Variant title="without locality">
|
||||
<InlineAddress :physicalAddress="{ ...address, locality: null }" />
|
||||
</Variant>
|
||||
</Story>
|
||||
</template>
|
||||
<script lang="ts" setup>
|
||||
import { IAddress } from "@/types/address.model";
|
||||
import { reactive } from "vue";
|
||||
import InlineAddress from "./InlineAddress.vue";
|
||||
|
||||
const address = reactive<IAddress>({
|
||||
description: "Locaux Motiv",
|
||||
street: "10 Rue Jangot",
|
||||
locality: "Lyon",
|
||||
postalCode: "69007",
|
||||
region: "Auvergne Rhône-Alpes",
|
||||
country: "France",
|
||||
type: "",
|
||||
timezone: "Europe/Dublin",
|
||||
});
|
||||
</script>
|
||||
35
src/components/Address/InlineAddress.vue
Normal file
35
src/components/Address/InlineAddress.vue
Normal file
@@ -0,0 +1,35 @@
|
||||
<template>
|
||||
<div
|
||||
class="truncate flex gap-1"
|
||||
dir="auto"
|
||||
:title="
|
||||
isDescriptionDifferentFromLocality
|
||||
? `${physicalAddress.description}, ${physicalAddress.locality}`
|
||||
: physicalAddress.description
|
||||
"
|
||||
>
|
||||
<MapMarker />
|
||||
<span v-if="physicalAddress.locality">
|
||||
{{ physicalAddress.locality }}
|
||||
</span>
|
||||
<span v-else>
|
||||
{{ physicalAddress.description }}
|
||||
</span>
|
||||
</div>
|
||||
</template>
|
||||
<script lang="ts" setup>
|
||||
import { IAddress } from "@/types/address.model";
|
||||
import MapMarker from "vue-material-design-icons/MapMarker.vue";
|
||||
import { computed } from "vue";
|
||||
|
||||
const props = defineProps<{
|
||||
physicalAddress: IAddress;
|
||||
}>();
|
||||
|
||||
const isDescriptionDifferentFromLocality = computed<boolean>(() => {
|
||||
return (
|
||||
props.physicalAddress?.description !== props.physicalAddress?.locality &&
|
||||
props.physicalAddress?.description !== undefined
|
||||
);
|
||||
});
|
||||
</script>
|
||||
Reference in New Issue
Block a user