@citizenplane/pimp 9.14.0 → 9.14.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@citizenplane/pimp",
3
- "version": "9.14.0",
3
+ "version": "9.14.1",
4
4
  "scripts": {
5
5
  "dev": "storybook dev -p 8080",
6
6
  "build-storybook": "storybook build --output-dir ./docs",
@@ -17,10 +17,10 @@
17
17
  <thead class="cpTable__header">
18
18
  <tr class="cpTable__row cpTable__row--header">
19
19
  <th
20
- v-for="column in visibleColumns"
20
+ v-for="(column, index) in visibleColumns"
21
21
  :key="column.id"
22
22
  class="cpTable__column"
23
- :style="getColumnStyle(column)"
23
+ :style="getColumnStyle(column, index)"
24
24
  >
25
25
  <slot :column="column" name="column">
26
26
  {{ column.name }}
@@ -200,6 +200,8 @@ const props = withDefaults(defineProps<Props>(), {
200
200
 
201
201
  const emit = defineEmits<Emits>()
202
202
 
203
+ const FULL_WIDTH_SIZE = 1000
204
+
203
205
  const LoaderColor = '#5341F9'
204
206
 
205
207
  const uniqueId = useId()
@@ -262,10 +264,25 @@ const getVisibleColumnsIds = () => {
262
264
  return normalizedColumns.value.filter(({ isHidden, isProtected }) => !isHidden || isProtected).map(({ id }) => id)
263
265
  }
264
266
 
267
+ const fullWidthColumn = computed(() => normalizedColumns.value.find(({ isFull }) => isFull))
268
+
269
+ const hasAFullWidthColumnVisible = computed(() => {
270
+ if (!fullWidthColumn.value) return false
271
+ return columnsModel.value.includes(fullWidthColumn.value.id)
272
+ })
273
+
274
+ const isLastColumn = (idx: number) => idx === visibleColumns.value.length - 1
275
+
265
276
  const columnsModel = ref<string[]>(getVisibleColumnsIds())
266
277
 
267
278
  watch(columnsModel, (newColumnsModel) => {
268
- const newColumns = normalizedColumns.value.map((col) => ({ ...col, isHidden: !newColumnsModel.includes(col.id) }))
279
+ const newColumns = normalizedColumns.value.map((col) => {
280
+ return {
281
+ ...col,
282
+ isHidden: !newColumnsModel.includes(col.id),
283
+ }
284
+ })
285
+
269
286
  emit('onColumnsChanged', newColumns)
270
287
  })
271
288
 
@@ -481,12 +498,18 @@ const resetScrollPosition = () => {
481
498
  }
482
499
  }
483
500
 
484
- const getColumnStyle = (columnPayload: CpTableColumnObject) => {
485
- const formattedWidth = columnPayload?.width && `${columnPayload.width}px`
501
+ const getColumnStyle = (column: CpTableColumnObject, idx: number) => {
502
+ let width: string | undefined
503
+
504
+ if (!hasAFullWidthColumnVisible.value && isLastColumn(idx)) {
505
+ width = `${FULL_WIDTH_SIZE}px`
506
+ } else if (column.width) {
507
+ width = `${column.width}px`
508
+ }
486
509
 
487
510
  return {
488
- width: formattedWidth,
489
- textAlign: columnPayload.textAlign,
511
+ width,
512
+ textAlign: column.textAlign,
490
513
  }
491
514
  }
492
515
 
@@ -1,5 +1,6 @@
1
1
  export interface CpTableColumnObject {
2
2
  id: string
3
+ isFull?: boolean
3
4
  isHidden?: boolean
4
5
  isProtected?: boolean
5
6
  name: string
@@ -14,6 +14,7 @@ const meta = {
14
14
  backgrounds: {
15
15
  default: 'dark',
16
16
  },
17
+ layout: 'padded',
17
18
  },
18
19
  decorators: [
19
20
  () => ({ template: '<div style="padding: 20px; border-radius: 8px; background-color: #fff;"><story/></div>' }),
@@ -66,26 +67,13 @@ export const Default: Story = {
66
67
  }
67
68
 
68
69
  export const EnableColumnEdition: Story = {
69
- args: {
70
- ...Default.args,
71
- columns: [
72
- { id: 'name', name: 'Name' },
73
- { id: 'age', name: 'Age' },
74
- { id: 'email', name: 'Email' },
75
- { id: 'status', name: 'Status' },
76
- ],
77
- enableColumnEdition: true,
78
- },
79
- }
80
-
81
- export const EnableColumnEditionWithDefault: Story = {
82
70
  args: {
83
71
  ...Default.args,
84
72
  columns: [
85
73
  { id: 'name', name: 'Name', isProtected: true },
86
74
  { id: 'age', name: 'Age', isHidden: true, isProtected: true },
87
75
  { id: 'email', name: 'Email', isHidden: false },
88
- { id: 'status', name: 'Status' },
76
+ { id: 'status', name: 'Status', isFull: true },
89
77
  ],
90
78
  enableColumnEdition: true,
91
79
  },