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

Feat/384 select global refactoring #394

Merged
merged 42 commits into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
35d50b6
feat: [Select] - related #384 - global refacto (wip)
mattgoud Oct 14, 2024
1db2e5b
feat: [Select] - related #384 - global refacto (style wip)
mattgoud Oct 15, 2024
e9c0083
feat: [Select] - related #384 - add translations, style(wip), add new…
mattgoud Oct 16, 2024
7a31706
feat: [Select] - related #384 - initialize selectedOptions with model…
mattgoud Oct 16, 2024
97d236f
feat: [Select] - related #384 - change puik-option logic (select even…
mattgoud Oct 17, 2024
2244ca4
feat: [Select] - related #384 - separate v-model refs between single…
mattgoud Oct 17, 2024
bb50b56
feat: [Select] - related #384 - implement puik-option via slot
mattgoud Oct 18, 2024
ce8102a
feat: [Select] - related #384 -fix puik-option reactivity when using …
mattgoud Oct 19, 2024
ca4bd8b
feat: [Select] - replace v-if directive by v-show instead to display …
mattgoud Oct 24, 2024
193e308
feat: [refacto-select] #384 - change select payload if option is dese…
mattgoud Nov 8, 2024
7a99358
feat: [refacto-select] #384 - add close event (option) and open event…
mattgoud Nov 12, 2024
b9c74d8
feat: [refacto-select] #384 - create puik-group-options component, fi…
mattgoud Nov 13, 2024
3461d27
feat: [refacto-select] #384 - improve accessibility, keyboard handlin…
mattgoud Nov 14, 2024
07e8145
feat: [select] - related #384 - form case to send data : add value in…
mattgoud Nov 15, 2024
bc9d181
feat: [selet-refacto] - related #384 - improve searcheable feature (f…
mattgoud Nov 18, 2024
b55a3e6
Merge branch 'main' into feat/384-select-global-refactoring
mattgoud Nov 19, 2024
301ab81
feat: [select-refacto] - related #384 - fix style error input, improv…
mattgoud Nov 20, 2024
2a9aebe
feat: [select-refacto] - related #384 - improve accessiblity (ARIA ta…
mattgoud Nov 21, 2024
0f20fa3
feat: [select-refacto] - related #384 - keyboard Handling (wip)
mattgoud Nov 21, 2024
2af8313
feat: [select-refacto] - related #384 - fix keyboard and mouse confli…
mattgoud Nov 21, 2024
40d743a
feat: [select-refacto] - related #384 - fix toggleSelectAll feature f…
mattgoud Nov 22, 2024
0e1f032
feat: [select-refacto] - related #384 - close dropdown on tab keydown
mattgoud Nov 23, 2024
deaf119
feat: [select-refacto] - add bg-red-50 on Input error, add prependInp…
mattgoud Nov 25, 2024
657258a
feat: [select-refacto] - handle case where selectedOptions are not an…
mattgoud Nov 27, 2024
dff2984
feat: [select-refacto][pagination-large]- fix select components in pa…
mattgoud Nov 28, 2024
5293e45
feat: [select-refacto] : if the dropdown is displayed outside the vie…
mattgoud Nov 29, 2024
f113922
feat: [pagination] - add test (id prop), and update stories
mattgoud Nov 29, 2024
c775553
feat: [select-refacto] - add dataTest and name props
mattgoud Nov 29, 2024
9d6789f
docs: [select-refacto] - update stories
mattgoud Dec 9, 2024
79ecdc6
feat: [select-refacto] - search feature: display no results placehol…
mattgoud Dec 10, 2024
3ca9d72
docs: [select-refacto] - update select, create option stories (wip)
mattgoud Dec 11, 2024
e86b722
docs: [select-refacto] - update select/options/groups-options stories…
mattgoud Dec 12, 2024
1c259ff
docs: [select-refacto] - fix indeterminate state of multi-select, upd…
mattgoud Dec 13, 2024
66a3759
test: [select-refacto] - refacto tests
mattgoud Dec 16, 2024
8451842
test: [select-refacto] - add tests for groupOptions and option compon…
mattgoud Dec 17, 2024
92dddfb
feat: [select-refacto] - refacto option type, update stories of optio…
mattgoud Dec 17, 2024
426d43a
docs: [select-refacto] - option section: listing data-test attributes
mattgoud Dec 17, 2024
a9a31f2
feat: [refacto-select] - related #384 : delete useless PuikGroupOptio…
mattgoud Dec 18, 2024
69c105a
feat: [refacto-select] - related #384 : add z-index prop (on dropdown…
mattgoud Dec 18, 2024
9fea83a
Merge branch 'main' into feat/384-select-global-refactoring
mattgoud Dec 20, 2024
c4416a3
Merge branch 'main' into feat/384-select-global-refactoring
mattgoud Jan 15, 2025
cb00bdc
feat: [useSnackbar] - related #384 - fix data-test name of pagination…
mattgoud Jan 15, 2025
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
2 changes: 2 additions & 0 deletions packages/components/group-options/style/css.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import '@prestashopcorp/puik-components/base/style/css';
import '@prestashopcorp/puik-theme/puik-group-options.css';
2 changes: 2 additions & 0 deletions packages/components/group-options/style/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import '@prestashopcorp/puik-components/base/style';
import '@prestashopcorp/puik-theme/src/puik-group-options.scss';
1 change: 1 addition & 0 deletions packages/components/option/style/css.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import '@prestashopcorp/puik-components/base/style/css';
import '@prestashopcorp/puik-theme/puik-option.css';
import '@prestashopcorp/puik-theme/puik-checkbox.css';
import '@prestashopcorp/puik-theme/puik-icon.css';
1 change: 1 addition & 0 deletions packages/components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"@headlessui/vue": "^1.7.22",
"@popperjs/core": "^2.11.8",
"@prestashopcorp/puik-theme": "workspace:*",
"@vueuse/components": "^11.1.0",
"@vueuse/core": "^10.9.0",
"radix-vue": "^1.7.4",
"sortablejs": "^1.15.2",
Expand Down
1 change: 1 addition & 0 deletions packages/components/pagination/src/pagination-large.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type PaginationLarge from './pagination-large.vue';

export interface PaginationLargeProps {
id: string
page: number
itemsPerPage: number
itemsPerPageOptions: number[]
Expand Down
29 changes: 23 additions & 6 deletions packages/components/pagination/src/pagination-large.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,29 +26,34 @@

<div class="puik-pagination__jumper">
<puik-select
:id="`${props.id}__select-jumper`"
:key="page"
:model-value="page"
:disabled="disabled"
:data-test="
dataTest != undefined ? `pageSelector-${dataTest}` : undefined
"
class="puik-pagination__select"
:open="openJumper"
@update:model-value="emit('update:page', $event)"
>
<puik-option
v-for="index in maxPage"
:key="`puik-pagination__page-selector__option-${index}`"
:value="index"
v-for="pageNb in maxPage"
:key="`puik-pagination__page-selector__option-${pageNb}`"
:label="pageNb"
:value="pageNb"
:is-selected="page === pageNb"
:data-test="
dataTest != undefined
? `pageSelectorOption-${dataTest}-${index}`
? `pageSelectorOption-${dataTest}-${pageNb}`
: undefined
"
@select="(payload) => emit('update:page', payload.value)"
@open="(state) => openJumper = state"
>
{{ index }}
{{ pageNb }}
</puik-option>
</puik-select>

<span class="puik-pagination__jumper-description">
{{ t('puik.pagination.large.jumperDescription', { maxPage }) }}
</span>
Expand Down Expand Up @@ -76,14 +81,22 @@
</span>
<puik-select
v-if="displayItemsPerPage"
:id="`${props.id}__select-items-per-page`"
:key="currentItemsPerPage"
v-model="currentItemsPerPage"
class="puik-pagination__items-per-page-select"
:open="openItemPerPages"
@update:model-value="emit('update:itemsPerPage', currentItemsPerPage)"
>
<puik-option
v-for="item in itemsPerPageOptions"
:key="`puik-pagination__items-per-page-select__option-${item}`"
:label="item"
:value="item"
:is-selected="currentItemsPerPage === item"
class="puik-pagination__items-per-page-select__option"
@select="(payload) => currentItemsPerPage = payload.value"
@open="(state) => openItemPerPages = state"
>
{{ item }}
</puik-option>
Expand All @@ -96,6 +109,7 @@ import { PuikSelect, PuikOption } from '@prestashopcorp/puik-components/select';
import { PuikButton } from '@prestashopcorp/puik-components/button';
import { useLocale } from '@prestashopcorp/puik-locale';
import { type PaginationLargeProps } from './pagination-large';
import { ref } from 'vue';
defineOptions({
name: 'PuikPaginationLarge'
});
Expand All @@ -110,4 +124,7 @@ const emit = defineEmits<{
const currentItemsPerPage = useVModel(props, 'itemsPerPage', emit);

const { t } = useLocale();

const openJumper = ref(false);
const openItemPerPages = ref(false);
</script>
1 change: 1 addition & 0 deletions packages/components/pagination/src/pagination-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type PaginationLoader from './pagination-loader.vue';

export interface PaginationLoaderProps {
modelValue?: number
id: string
disabled?: boolean
label?: string
loaderButtonLabel?: string
Expand Down
1 change: 1 addition & 0 deletions packages/components/pagination/src/pagination-medium.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type PaginationMedium from './pagination-medium.vue';

export interface PaginationMediumProps {
modelValue?: number
id: string
disabled?: boolean
totalItem: number
maxPage: number
Expand Down
1 change: 1 addition & 0 deletions packages/components/pagination/src/pagination-mobile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type PaginationMobile from './pagination-mobile.vue';

export interface PaginationMobileProps {
modelValue?: number
id: string
disabled?: boolean
maxPage: number
label?: string
Expand Down
1 change: 1 addition & 0 deletions packages/components/pagination/src/pagination-small.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type PaginationSmall from './pagination-small.vue';

export interface PaginationSmallProps {
modelValue?: number
id: string
disabled?: boolean
maxPage: number
label?: string
Expand Down
1 change: 1 addition & 0 deletions packages/components/pagination/src/pagination.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export enum PuikPaginationVariants {
}

export interface PaginationProps {
id?: string
variant?: `${PuikPaginationVariants}`
totalItem: number
itemsPerPage?: number
Expand Down
8 changes: 8 additions & 0 deletions packages/components/pagination/src/pagination.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<template>
<nav
:id="props.id"
class="puik-pagination"
:class="[`puik-pagination--${variant}`]"
role="navigation"
Expand All @@ -8,6 +9,7 @@
>
<pagination-loader
v-if="variant === PuikPaginationVariants.Loader"
:id="`${props.id}--loader`"
v-model="currentPage"
:data-test="dataTest"
:disabled="loaderButtonDisabled"
Expand All @@ -21,13 +23,15 @@
>
<pagination-mobile
v-if="variant === PuikPaginationVariants.Mobile"
:id="`${props.id}--mobile`"
v-model="currentPage"
v-bind="commonPaginationProps"
:data-test="dataTest"
/>

<pagination-small
v-if="variant === PuikPaginationVariants.Small"
:id="`${props.id}--small`"
v-model="currentPage"
v-bind="commonPaginationProps"
:data-test="dataTest"
Expand All @@ -36,6 +40,7 @@

<pagination-medium
v-if="variant === PuikPaginationVariants.Medium && !disabled"
:id="`${props.id}--medium`"
v-model="currentPage"
v-bind="commonPaginationProps"
:data-test="dataTest"
Expand All @@ -45,6 +50,7 @@

<pagination-large
v-if="variant === PuikPaginationVariants.Large"
:id="`${props.id}--large`"
v-model:page="currentPage"
:data-test="dataTest"
:display-items-per-page="displayItemsPerPage"
Expand All @@ -61,6 +67,7 @@

<script setup lang="ts">
import { computed, watch } from 'vue';
import { generateId } from '@prestashopcorp/puik-utils';
import { useLocale } from '@prestashopcorp/puik-locale';
import { type PaginationProps, PuikPaginationVariants } from './pagination';

Expand All @@ -75,6 +82,7 @@ defineOptions({
});

const props = withDefaults(defineProps<PaginationProps>(), {
id: `puik-pagination-${generateId()}`,
variant: PuikPaginationVariants.Medium,
itemsPerPage: 5,
itemsPerPageOptions: () => [5, 10, 15],
Expand Down
13 changes: 13 additions & 0 deletions packages/components/pagination/stories/pagination.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,19 @@ export default {
title: 'Components/Pagination',
component: PuikPagination,
argTypes: {
id: {
control: 'text',
description:
'Sets the id HTML attribute of puik-pagination. If this prop is not configured, an id will be automatically generated using this pattern: puik-pagination-{randomNumber}',
table: {
defaultValue: {
summary: 'puik-pagination-{randomNumber}'
},
type: {
summary: 'string'
}
}
},
variant: {
control: 'select',
options: paginationVariants,
Expand Down
25 changes: 9 additions & 16 deletions packages/components/pagination/test/pagination.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ describe('Pagination tests', () => {

const findItemsPerPageSelect = () =>
wrapper.find('.puik-pagination__items-per-page-select');
const findAllOptions = (select) => select.findAllComponents(PuikOption);
const findAllOptions = (select: any) => select.findAllComponents(PuikOption);

const factory = (
props: PaginationProps,
Expand All @@ -54,6 +54,14 @@ describe('Pagination tests', () => {
expect(wrapper).toBeTruthy();
});

it('as id prop value is "puik-pagination-id", id html attribute of puik-pagination should be "puik-pagination-id"', () => {
factory({
...propsData,
id: 'puik-pagination-id'
});
expect(findPagination().attributes().id).toBe('puik-pagination-id');
});

it('should display a medium pagination by default', () => {
factory(propsData);
expect(findPagination().classes()).toContain('puik-pagination--medium');
Expand Down Expand Up @@ -243,21 +251,6 @@ describe('Pagination tests', () => {
expect(findNextButtonText().text()).toBe(nextText);
});

it('should click page change active class and aria-current', async () => {
factory({ ...propsData, variant: PuikPaginationVariants.Large });

const findSelect = () => wrapper.find('.puik-pagination__select');
const findAllOptions = () => wrapper.findAllComponents(PuikOption);

// Click first pager button
await findSelect().trigger('click');
await findAllOptions()[5].trigger('click');
await nextTick();
expect(findPaginationComponent().emitted('update:page')?.[0]).toStrictEqual(
[5]
);
});

it('should emit when selecting item per page', async () => {
factory({ ...propsData, variant: PuikPaginationVariants.Large });

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
>
<puik-button
:aria-current="isCurrentStep ? 'step' : undefined"
:aria-label="step"
:aria-label="`${step}`"
:disabled="disabled"
:left-icon="isCompleted ? 'check' : undefined"
:variant="buttonVariant"
Expand Down
2 changes: 1 addition & 1 deletion packages/components/select/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ export default PuikSelect;

export const PuikOption = Option;

export * from './src/select';
export * from './src/option';
export * from './src/select';
16 changes: 11 additions & 5 deletions packages/components/select/src/option.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
/* eslint-disable @typescript-eslint/member-delimiter-style */
import '@prestashopcorp/puik-components/option/style/css';
import type Option from './option.vue';

export interface DefaultOption {
label: string | number
value: string | number | Record<string, any>
export interface OptionType {
[key: string]: any
}

export interface OptionProps {
value: string | number | Record<string, any>
label?: string | number
value?: string | number
disabled?: boolean
isSelected?: boolean
multiSelect?: boolean
dataTest?: string
}

export type OptionEmits = {
'open': [state: boolean],
'select': [payload: any]
};

export type OptionInstance = InstanceType<typeof Option>;
Loading
Loading