@citizenplane/pimp 16.2.1 → 16.3.0

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": "16.2.1",
3
+ "version": "16.3.0",
4
4
  "scripts": {
5
5
  "dev": "storybook dev -p 8081",
6
6
  "build-storybook": "storybook build --output-dir ./docs",
@@ -20,6 +20,7 @@
20
20
  v-for="column in visibleColumns"
21
21
  :key="column.id"
22
22
  class="cpTable__column"
23
+ :class="getColumnClasses(column.id)"
23
24
  :style="getColumnStyle(column)"
24
25
  >
25
26
  <slot :column="column" name="column">
@@ -49,12 +50,11 @@
49
50
  >
50
51
  <slot name="row" :row="rowData">
51
52
  <td
52
- v-for="(cellValue, cellKey, cellIndex) in rowData"
53
+ v-for="(cellValue, cellKey) in rowData"
53
54
  :key="`${cellKey}_${rowIndex}`"
54
55
  class="cpTable__cell"
55
56
  :class="getCellClasses(cellKey)"
56
57
  :colspan="getColspan(cellKey)"
57
- :style="getCellStyle(cellKey, cellIndex)"
58
58
  >
59
59
  <slot :cell="cellValue" :name="cellKey">
60
60
  <span v-if="isFullWidthRow(rowData)">{{ cellValue }}</span>
@@ -136,6 +136,7 @@ import CpTableEmptyState from '@/components/CpTableEmptyState.vue'
136
136
  import { camelize, decamelize } from '@/helpers/string'
137
137
 
138
138
  import { PAGINATION_FORMATS, RESERVED_KEYS, VISIBLE_ROWS_MAX } from '@/constants'
139
+ import { capitalizeFirstLetter } from '@/helpers'
139
140
 
140
141
  interface Emits {
141
142
  (evt: 'onRowClick', data: Record<string, unknown>): void
@@ -544,6 +545,8 @@ const resetScrollPosition = () => {
544
545
  }
545
546
  }
546
547
 
548
+ const getColumnClasses = (columnId: string) => `cpTable__column--is${capitalizeFirstLetter(columnId)}`
549
+
547
550
  const getColumnStyle = (column: CpTableColumnObject) => {
548
551
  let width: string | undefined
549
552
 
@@ -555,17 +558,7 @@ const getColumnStyle = (column: CpTableColumnObject) => {
555
558
  width = `${column.width}px`
556
559
  }
557
560
 
558
- return {
559
- width,
560
- textAlign: column.textAlign,
561
- }
562
- }
563
-
564
- const getCellStyle = (cellKey: RESERVED_KEYS, cellIndex: number) => {
565
- if (isFullWidthCell(cellKey)) return null
566
- return {
567
- textAlign: visibleColumns.value[cellIndex]?.textAlign,
568
- }
561
+ return { width }
569
562
  }
570
563
 
571
564
  const getRowClasses = (rowData: Record<string, unknown>, rowIndex: number) => {
@@ -34,7 +34,6 @@ import CpItemActions from './CpItemActions.vue'
34
34
  import CpLoader from './CpLoader.vue'
35
35
  import CpMenuItem from './CpMenuItem.vue'
36
36
  import CpMultiselect from './CpMultiselect.vue'
37
- import CpPartnerBadge from './CpPartnerBadge.vue'
38
37
  import CpRadio from './CpRadio.vue'
39
38
  import CpRadioGroup from './CpRadioGroup.vue'
40
39
  import CpRadioNew from './CpRadioNew.vue'
@@ -103,7 +102,6 @@ const Components = {
103
102
  CpIcon,
104
103
  CpTelInput,
105
104
  CpTooltip,
106
- CpPartnerBadge,
107
105
  CpAirlineLogo,
108
106
  IconAirline,
109
107
  IconOta,
@@ -4,7 +4,6 @@ export interface CpTableColumnObject {
4
4
  isHidden?: boolean
5
5
  isProtected?: boolean
6
6
  name: string
7
- textAlign?: 'left' | 'center' | 'right'
8
7
  width?: number
9
8
  }
10
9
 
@@ -4,7 +4,6 @@ export type { ToggleColors } from './colors/ToggleColors'
4
4
  export { HeadingLevels } from './Heading'
5
5
  export { PAGINATION_FORMATS, RESERVED_KEYS, VISIBLE_ROWS_MAX } from './CpTableConfig'
6
6
  export type { Sizes } from './Sizes'
7
- export { PartnerTypes } from './PartnerTypes'
8
7
 
9
8
  export { CustomCpIcons } from './CpCustomIcons'
10
9
  export { Intent } from './Intent'
@@ -1,90 +0,0 @@
1
- <template>
2
- <div class="cpPartnerBadge" :class="componentDynamicClasses">
3
- <slot name="icon">
4
- <component :is="dynamicBadgeProps.icon" class="cpPartnerBadge__icon" />
5
- </slot>
6
- </div>
7
- </template>
8
-
9
- <script setup lang="ts">
10
- import { computed } from 'vue'
11
-
12
- import IconAirline from '@/components/icons/IconAirline.vue'
13
- import IconOta from '@/components/icons/IconOta.vue'
14
- import IconSupplier from '@/components/icons/IconSupplier.vue'
15
- import IconThirdParty from '@/components/icons/IconThirdParty.vue'
16
-
17
- import { PartnerTypes } from '@/constants'
18
- import type { Sizes } from '@/constants'
19
-
20
- interface Props {
21
- size?: Sizes
22
- type?: PartnerTypes
23
- }
24
-
25
- const props = withDefaults(defineProps<Props>(), {
26
- size: 'md',
27
- type: PartnerTypes.THIRDPARTY,
28
- })
29
-
30
- const dynamicBadgeProps = computed(() => {
31
- switch (props.type) {
32
- case PartnerTypes.OTA:
33
- return { classModifier: 'isOta', icon: IconOta }
34
- case PartnerTypes.AIRLINE:
35
- return { classModifier: 'isAirline', icon: IconAirline }
36
- case PartnerTypes.SUPPLIER:
37
- return { classModifier: 'isSupplier', icon: IconSupplier }
38
- case PartnerTypes.THIRDPARTY:
39
- default:
40
- return { classModifier: 'isThirdParty', icon: IconThirdParty }
41
- }
42
- })
43
-
44
- const componentDynamicClasses = computed(() => {
45
- return [`cpPartnerBadge--${props.size}`, `cpPartnerBadge--${dynamicBadgeProps.value.classModifier}`]
46
- })
47
- </script>
48
-
49
- <style lang="scss">
50
- .cpPartnerBadge {
51
- display: inline-flex;
52
- padding: var(--cp-spacing-xs);
53
- align-items: center;
54
- justify-content: center;
55
- border-radius: var(--cp-radius-sm);
56
- color: var(--cp-text-white);
57
-
58
- &--isOta {
59
- background-color: var(--cp-background-warning-solid);
60
- }
61
-
62
- &--isAirline {
63
- background-color: var(--cp-background-blue-solid);
64
- }
65
-
66
- &--isSupplier {
67
- background-color: var(--cp-background-magenta-solid);
68
- }
69
-
70
- &--isThirdParty {
71
- background-color: var(--cp-background-pink-solid);
72
- }
73
-
74
- > * {
75
- width: var(--cp-dimensions-5);
76
- height: var(--cp-dimensions-5);
77
- aspect-ratio: 1/1;
78
- }
79
-
80
- &--sm > * {
81
- width: var(--cp-dimensions-4);
82
- height: var(--cp-dimensions-4);
83
- }
84
-
85
- &--xs > * {
86
- width: var(--cp-dimensions-3);
87
- height: var(--cp-dimensions-3);
88
- }
89
- }
90
- </style>
@@ -1,6 +0,0 @@
1
- export enum PartnerTypes {
2
- OTA = 'ota',
3
- AIRLINE = 'airline',
4
- SUPPLIER = 'supplier',
5
- THIRDPARTY = 'thirdParty',
6
- }
@@ -1,143 +0,0 @@
1
- import type { Meta, StoryObj } from '@storybook/vue3-vite'
2
-
3
- import CpPartnerBadge from '@/components/CpPartnerBadge.vue'
4
-
5
- import { PartnerTypes } from '@/constants'
6
- import { docCellStyle, docLabelStyle, docRowWrapStyle } from '@/stories/documentationStyles'
7
-
8
- const partnerSizes = ['2xs', 'xs', 'sm', 'md', 'lg', 'xl', '2xl', '3xl', '4xl'] as const
9
-
10
- const meta = {
11
- title: 'Atoms/CpPartnerBadge',
12
- component: CpPartnerBadge,
13
- parameters: {
14
- docs: {
15
- description: {
16
- component:
17
- 'A badge component that displays partner type icons with different background colors based on the partner type. Supports OTA, Airline, Supplier, and Third Party partner types.',
18
- },
19
- },
20
- },
21
- argTypes: {
22
- type: {
23
- control: 'select',
24
- options: Object.values(PartnerTypes),
25
- description: 'The type of partner (determines icon and background color)',
26
- table: {
27
- type: { summary: 'string' },
28
- defaultValue: { summary: 'ota' },
29
- },
30
- },
31
- size: {
32
- control: 'select',
33
- options: partnerSizes,
34
- description: 'The size of the badge',
35
- table: {
36
- type: { summary: 'string' },
37
- defaultValue: { summary: 'md' },
38
- },
39
- },
40
- },
41
- tags: ['autodocs'],
42
- } satisfies Meta<typeof CpPartnerBadge>
43
-
44
- export default meta
45
-
46
- type Story = StoryObj<typeof meta>
47
-
48
- type PartnerBadgeStoryArgs = NonNullable<Story['args']>
49
-
50
- const defaultTemplate = '<CpPartnerBadge v-bind="args" />'
51
- const defaultRender = (args: PartnerBadgeStoryArgs) => ({
52
- components: { CpPartnerBadge },
53
- setup() {
54
- return { args }
55
- },
56
- template: defaultTemplate,
57
- })
58
-
59
- /**
60
- * Default partner badge. Use the controls to experiment with each prop in
61
- * isolation.
62
- */
63
- export const Default: Story = {
64
- args: {
65
- type: PartnerTypes.OTA,
66
- },
67
- render: defaultRender,
68
- }
69
-
70
- /* -------------------------------------------------------------------------- */
71
- /* Types */
72
- /* -------------------------------------------------------------------------- */
73
-
74
- /**
75
- * Every partner type rendered side by side. Each type gets its own icon and
76
- * background color.
77
- */
78
- export const Types: Story = {
79
- parameters: { controls: { disable: true } },
80
- render: () => ({
81
- components: { CpPartnerBadge },
82
- setup() {
83
- const entries = Object.entries(PartnerTypes)
84
- return { entries, docCellStyle, docLabelStyle, docRowWrapStyle }
85
- },
86
- template: `
87
- <div :style="docRowWrapStyle">
88
- <div v-for="[name, type] in entries" :key="type" :style="docCellStyle">
89
- <span :style="docLabelStyle">{{ name.toLowerCase() }}</span>
90
- <CpPartnerBadge :type="type" />
91
- </div>
92
- </div>
93
- `,
94
- }),
95
- }
96
-
97
- /* -------------------------------------------------------------------------- */
98
- /* Sizes */
99
- /* -------------------------------------------------------------------------- */
100
-
101
- /**
102
- * All sizes rendered side by side, from `2xs` to `4xl`.
103
- */
104
- export const Sizes: Story = {
105
- parameters: { controls: { disable: true } },
106
- render: () => ({
107
- components: { CpPartnerBadge },
108
- setup() {
109
- return { partnerSizes, PartnerTypes, docCellStyle, docLabelStyle, docRowWrapStyle }
110
- },
111
- template: `
112
- <div :style="docRowWrapStyle">
113
- <div v-for="size in partnerSizes" :key="size" :style="docCellStyle">
114
- <span :style="docLabelStyle">{{ size }}</span>
115
- <CpPartnerBadge :type="PartnerTypes.OTA" :size="size" />
116
- </div>
117
- </div>
118
- `,
119
- }),
120
- }
121
-
122
- /* -------------------------------------------------------------------------- */
123
- /* Slots */
124
- /* -------------------------------------------------------------------------- */
125
-
126
- /**
127
- * Override the default icon through the `#icon` slot.
128
- */
129
- export const WithCustomIcon: Story = {
130
- render: () => ({
131
- components: { CpPartnerBadge },
132
- setup() {
133
- return { PartnerTypes }
134
- },
135
- template: `
136
- <CpPartnerBadge :type="PartnerTypes.OTA">
137
- <template #icon>
138
- <cp-icon type="plus" />
139
- </template>
140
- </CpPartnerBadge>
141
- `,
142
- }),
143
- }