@citizenplane/pimp 18.16.2 → 18.17.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": "18.16.2",
3
+ "version": "18.17.0",
4
4
  "scripts": {
5
5
  "dev": "storybook dev -p 8081",
6
6
  "build-storybook": "storybook build --output-dir ./docs",
@@ -10,7 +10,7 @@
10
10
  >
11
11
  <span class="cpToggleButton__leading">
12
12
  <slot name="leading">
13
- <cp-icon size="16" :type="leadingIcon" />
13
+ <cp-icon :size="dynamicIconSize" :type="leadingIcon" />
14
14
  </slot>
15
15
  </span>
16
16
  <span v-if="showLabel" class="cpToggleButton__label">
@@ -29,6 +29,7 @@ interface Props {
29
29
  isSelected?: boolean
30
30
  label?: string
31
31
  leadingIcon?: string
32
+ size?: 'sm' | 'md' | 'lg'
32
33
  }
33
34
 
34
35
  const props = withDefaults(defineProps<Props>(), {
@@ -36,6 +37,7 @@ const props = withDefaults(defineProps<Props>(), {
36
37
  disabled: false,
37
38
  label: '',
38
39
  leadingIcon: 'dashed-circle',
40
+ size: 'md',
39
41
  })
40
42
 
41
43
  const emit = defineEmits<{
@@ -46,13 +48,25 @@ const slots = useSlots()
46
48
 
47
49
  const showLabel = computed(() => !!props.label || !!slots.default)
48
50
 
49
- const dynamicClasses = computed(() => ({
50
- 'cpToggleButton--isSelected': props.isSelected,
51
- }))
51
+ const dynamicClasses = computed(() => {
52
+ return {
53
+ [`cpToggleButton--${props.size}`]: true,
54
+ 'cpToggleButton--isSelected': props.isSelected,
55
+ }
56
+ })
52
57
 
53
- const handleClick = (event: MouseEvent) => {
54
- emit('click', event)
55
- }
58
+ const dynamicIconSize = computed(() => {
59
+ switch (props.size) {
60
+ case 'lg':
61
+ return '20'
62
+ case 'md':
63
+ case 'sm':
64
+ default:
65
+ return '16'
66
+ }
67
+ })
68
+
69
+ const handleClick = (event: MouseEvent) => emit('click', event)
56
70
  </script>
57
71
 
58
72
  <style lang="scss">
@@ -60,7 +74,6 @@ const handleClick = (event: MouseEvent) => {
60
74
  display: inline-flex;
61
75
  align-items: center;
62
76
  justify-content: center;
63
- padding: var(--cp-spacing-lg);
64
77
  border-radius: var(--cp-radius-md);
65
78
  background-color: var(--cp-background-primary);
66
79
  box-shadow:
@@ -71,8 +84,7 @@ const handleClick = (event: MouseEvent) => {
71
84
  transition:
72
85
  background-color 100ms ease-out,
73
86
  box-shadow 100ms ease-out,
74
- color 100ms ease-out,
75
- transform 100ms ease;
87
+ color 100ms ease-out;
76
88
 
77
89
  &:focus-visible {
78
90
  box-shadow:
@@ -97,10 +109,6 @@ const handleClick = (event: MouseEvent) => {
97
109
  color: var(--cp-text-secondary-hover);
98
110
  }
99
111
 
100
- &:active:not(:disabled) {
101
- transform: scale3d(0.97, 0.97, 1);
102
- }
103
-
104
112
  &__leading {
105
113
  display: flex;
106
114
  align-items: center;
@@ -117,6 +125,23 @@ const handleClick = (event: MouseEvent) => {
117
125
  pointer-events: none;
118
126
  }
119
127
 
128
+ &--sm {
129
+ padding: var(--cp-spacing-sm-md) var(--cp-spacing-md);
130
+ }
131
+
132
+ &--md {
133
+ padding: var(--cp-dimensions-2_5) var(--cp-spacing-lg);
134
+ }
135
+
136
+ &--lg {
137
+ padding: var(--cp-spacing-lg) var(--cp-spacing-xl);
138
+
139
+ .cpToggleButton__label {
140
+ font-size: var(--cp-text-size-md);
141
+ line-height: var(--cp-line-height-md);
142
+ }
143
+ }
144
+
120
145
  &--isSelected:not(:disabled) {
121
146
  background-color: var(--cp-background-accent-secondary);
122
147
  box-shadow:
@@ -0,0 +1,106 @@
1
+ <template>
2
+ <div class="cpQuantityCounter">
3
+ <button
4
+ :aria-label="decreaseLabel"
5
+ class="cpQuantityCounter__button"
6
+ :disabled="isDecrementDisabled"
7
+ type="button"
8
+ @click="decrement"
9
+ >
10
+ <cp-icon size="16" type="minus" />
11
+ </button>
12
+ <cp-transition-counter v-if="!disableAnimation" class="cpQuantityCounter__count" :counter-number="modelValue">
13
+ <span>{{ modelValue }}</span>
14
+ </cp-transition-counter>
15
+ <span v-else class="cpQuantityCounter__count">{{ modelValue }}</span>
16
+ <button
17
+ :aria-label="increaseLabel"
18
+ class="cpQuantityCounter__button cpQuantityCounter__button--isAccent"
19
+ :disabled="isIncrementDisabled"
20
+ type="button"
21
+ @click="increment"
22
+ >
23
+ <cp-icon size="16" type="plus" />
24
+ </button>
25
+ </div>
26
+ </template>
27
+
28
+ <script setup lang="ts">
29
+ import { computed } from 'vue'
30
+
31
+ import CpIcon from '@/components/CpIcon.vue'
32
+ import CpTransitionCounter from '@/components/CpTransitionCounter.vue'
33
+
34
+ interface Props {
35
+ decreaseLabel: string
36
+ disableAnimation?: boolean
37
+ increaseLabel: string
38
+ max?: number | null
39
+ min?: number
40
+ }
41
+
42
+ const props = withDefaults(defineProps<Props>(), { disableAnimation: false, max: null, min: 0 })
43
+
44
+ const modelValue = defineModel<number>({ required: true })
45
+
46
+ const isDecrementDisabled = computed(() => modelValue.value <= props.min)
47
+ const isIncrementDisabled = computed(() => props.max !== null && modelValue.value >= props.max)
48
+
49
+ const decrement = () => {
50
+ if (isDecrementDisabled.value) return
51
+ modelValue.value -= 1
52
+ }
53
+
54
+ const increment = () => {
55
+ if (isIncrementDisabled.value) return
56
+ modelValue.value += 1
57
+ }
58
+ </script>
59
+
60
+ <style lang="scss">
61
+ .cpQuantityCounter {
62
+ display: flex;
63
+ align-items: center;
64
+ padding: var(--cp-spacing-xs);
65
+ border-radius: var(--cp-radius-md-lg);
66
+ background: var(--cp-background-accent-primary);
67
+ gap: var(--cp-spacing-sm);
68
+
69
+ &__button {
70
+ display: flex;
71
+ align-items: center;
72
+ justify-content: center;
73
+ padding: var(--cp-spacing-sm-md);
74
+ border: fn.px-to-rem(1) solid var(--cp-border-soft);
75
+ border-radius: var(--cp-radius-md);
76
+ background: var(--cp-background-primary);
77
+ box-shadow: var(--cp-shadows-3xs);
78
+ color: var(--cp-text-primary);
79
+
80
+ @include mx.square-sizing(28);
81
+ @extend %u-focus-outline;
82
+
83
+ &:disabled {
84
+ border-color: transparent;
85
+ background: var(--cp-background-secondary);
86
+ box-shadow: none;
87
+ color: var(--cp-text-disabled);
88
+ }
89
+
90
+ &--isAccent {
91
+ color: var(--cp-text-accent-primary);
92
+ }
93
+ }
94
+
95
+ &__count {
96
+ display: flex;
97
+ width: fn.px-to-rem(24);
98
+ justify-content: center;
99
+ color: var(--cp-text-primary);
100
+ font-size: var(--cp-text-size-sm);
101
+ font-weight: 500;
102
+ line-height: var(--cp-text-sm-line-height);
103
+ text-align: center;
104
+ }
105
+ }
106
+ </style>
@@ -40,6 +40,7 @@ import CpMenu from './CpMenu.vue'
40
40
  import CpMenuItem from './CpMenuItem.vue'
41
41
  import CpMenuList from './CpMenuList.vue'
42
42
  import CpMultiselect from './CpMultiselect.vue'
43
+ import CpQuantityCounter from './CpQuantityCounter.vue'
43
44
  import CpRadio from './CpRadio.vue'
44
45
  import CpRadioGroup from './CpRadioGroup.vue'
45
46
  import CpRadioNew from './CpRadioNew.vue'
@@ -120,6 +121,7 @@ const Components = {
120
121
  CpSelect,
121
122
  CpSelectMenu,
122
123
  CpMultiselect,
124
+ CpQuantityCounter,
123
125
  CpCheckbox,
124
126
  CpRadio,
125
127
  CpRadioGroup,
@@ -244,6 +246,7 @@ export {
244
246
  CpMenuItem,
245
247
  CpMenuList,
246
248
  CpMultiselect,
249
+ CpQuantityCounter,
247
250
  CpRadio,
248
251
  CpRadioGroup,
249
252
  CpRadioNew,
@@ -6,10 +6,17 @@ import CpSwitch from '@/components/CpSwitch.vue'
6
6
 
7
7
  import { docCellStyle, docLabelStyle, docRowWrapStyle } from '@/stories/documentationStyles'
8
8
 
9
+ const buttonToggleSizes = ['sm', 'md', 'lg'] as const
10
+
9
11
  const meta = {
10
12
  title: 'Atoms/CpButtonToggle',
11
13
  component: CpButtonToggle,
12
14
  argTypes: {
15
+ size: {
16
+ control: 'select',
17
+ options: buttonToggleSizes,
18
+ description: 'The size of the toggle button.',
19
+ },
13
20
  isSelected: {
14
21
  control: 'boolean',
15
22
  description: 'Whether the toggle button is selected.',
@@ -48,10 +55,29 @@ export const Default: Story = {
48
55
  isSelected: false,
49
56
  disabled: false,
50
57
  leadingIcon: 'dashed-circle',
58
+ size: 'md',
51
59
  },
52
60
  render: defaultRender,
53
61
  }
54
62
 
63
+ export const Sizes: Story = {
64
+ parameters: { controls: { disable: true } },
65
+ render: () => ({
66
+ components: { CpButtonToggle },
67
+ setup() {
68
+ return { buttonToggleSizes, docCellStyle, docLabelStyle, docRowWrapStyle }
69
+ },
70
+ template: `
71
+ <div :style="docRowWrapStyle">
72
+ <div v-for="size in buttonToggleSizes" :key="size" :style="docCellStyle">
73
+ <span :style="docLabelStyle">{{ size }}</span>
74
+ <CpButtonToggle label="Title" :size="size" />
75
+ </div>
76
+ </div>
77
+ `,
78
+ }),
79
+ }
80
+
55
81
  export const States: Story = {
56
82
  parameters: { controls: { disable: true } },
57
83
  render: () => ({
@@ -0,0 +1,63 @@
1
+ import type { Meta, StoryObj } from '@storybook/vue3-vite'
2
+ import { ref } from 'vue'
3
+
4
+ import CpQuantityCounter from '@/components/CpQuantityCounter.vue'
5
+
6
+ const meta = {
7
+ title: 'Atoms/CpQuantityCounter',
8
+ component: CpQuantityCounter,
9
+ argTypes: {
10
+ decreaseLabel: {
11
+ control: 'text',
12
+ description: 'Aria-label for the decrease button',
13
+ },
14
+ disableAnimation: {
15
+ control: 'boolean',
16
+ description: 'Whether to render the count as a plain span instead of animating it',
17
+ },
18
+ increaseLabel: {
19
+ control: 'text',
20
+ description: 'Aria-label for the increase button',
21
+ },
22
+ max: {
23
+ control: 'number',
24
+ description: 'Maximum allowed value',
25
+ },
26
+ min: {
27
+ control: 'number',
28
+ description: 'Minimum allowed value',
29
+ },
30
+ modelValue: {
31
+ control: 'number',
32
+ description: 'The counter value',
33
+ },
34
+ },
35
+ } satisfies Meta<typeof CpQuantityCounter>
36
+
37
+ export default meta
38
+ type Story = StoryObj<typeof meta>
39
+
40
+ /**
41
+ * Default counter. Use the controls to experiment with each prop in isolation.
42
+ */
43
+ export const Default: Story = {
44
+ args: {
45
+ modelValue: 1,
46
+ min: 0,
47
+ max: 5,
48
+ decreaseLabel: 'Decrease',
49
+ increaseLabel: 'Increase',
50
+ },
51
+ render: (args) => ({
52
+ components: { CpQuantityCounter },
53
+ setup() {
54
+ const value = ref(1)
55
+ return { args, value }
56
+ },
57
+ template: `
58
+ <div style="padding: 20px;">
59
+ <CpQuantityCounter v-bind="args" v-model="value" />
60
+ </div>
61
+ `,
62
+ }),
63
+ }