Skip to content

Commit dda3013

Browse files
committed
Merge remote-tracking branch 'origin/master'
2 parents 75a0322 + d333e4d commit dda3013

File tree

7 files changed

+86
-38
lines changed

7 files changed

+86
-38
lines changed

src/components/Button/Button.vue

Lines changed: 37 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,25 @@
11
<template lang="pug">
22
div(
33
v-if="connectedDisclosure",
4-
:class="styles.ConnectedDisclosureWrapper"
4+
:key="generateUpdateKey('connected')",
5+
:class="styles.ConnectedDisclosureWrapper",
56
)
67
ButtonMarkup(
78
v-bind="buttonMarkupProps",
89
v-on="listeners",
910
)
1011
slot
1112
Popover(
12-
:active="disclosureActive",
1313
preferredAlignment="right",
14+
:active="disclosureActive",
1415
@close="toggleDisclosureActive",
1516
)
1617
template(#activator)
1718
button(
1819
type="button",
1920
:class="connectedDisclosureClassName",
2021
:aria-disabled="connectedDisclosureData.disabled",
21-
:tabIndex="connectedDisclosureData.disabled ? -1 : undefined"
22+
:tabIndex="connectedDisclosureData.disabled ? -1 : undefined",
2223
:aria-label="connectedDisclosureData.disclosureLabel",
2324
:aria-describedby="ariaDescribedBy",
2425
:aria-checked="ariaChecked",
@@ -40,6 +41,7 @@ ButtonMarkup(
4041
v-else,
4142
v-bind="buttonMarkupProps",
4243
v-on="listeners",
44+
:key="generateUpdateKey('markup')",
4345
)
4446
slot
4547
</template>
@@ -51,9 +53,7 @@ export default {
5153
</script>
5254

5355
<script setup lang="ts">
54-
import {
55-
computed, ref, useAttrs, useSlots,
56-
} from 'vue';
56+
import { computed, ref, useAttrs, useSlots } from 'vue';
5757
import { classNames, variationName } from '@/utilities/css';
5858
import CaretDownMinor from '@icons/CaretDownMinor.svg';
5959
import { handleMouseUpByBlurring } from '@/utilities/focus';
@@ -154,6 +154,8 @@ interface Props {
154154
dataPrimaryLink?: boolean;
155155
}
156156
157+
const MAX_RANDOM_NUMBER = 99999;
158+
157159
const props = withDefaults(defineProps<Props>(), {
158160
size: 'medium',
159161
disclosure: undefined,
@@ -164,22 +166,25 @@ const props = withDefaults(defineProps<Props>(), {
164166
const slots = useSlots();
165167
const attrs = useAttrs();
166168
169+
const hasChildren = !!slots.default;
170+
171+
const disclosureActive = ref<boolean>(false);
172+
167173
const listeners = computed(() => {
168174
const events = ['blur', 'click', 'focus', 'keydown', 'keypress', 'keyup', 'mouseover', 'touchstart', 'pointerdown'];
169175
const eventBindings: Record<string, unknown> = {};
176+
170177
for (const event of events) {
171178
const eventName = `on${capitalize(event)}`;
179+
172180
if (attrs[eventName]) {
173181
eventBindings[event] = attrs[eventName];
174182
}
175183
}
184+
176185
return eventBindings;
177186
});
178187
179-
const hasChildren = !!slots.default;
180-
181-
const disclosureActive = ref<boolean>(false);
182-
183188
const isDisabled = computed(() => props.disabled || props.loading);
184189
185190
const className = computed(() => {
@@ -207,16 +212,16 @@ const className = computed(() => {
207212
});
208213
209214
const connectedDisclosureClassName = computed(() => {
210-
const textAlignVariantion = props.textAlign
215+
const textAlignVariation = props.textAlign
211216
&& variationName('textAlign', props.textAlign) as keyof typeof styles;
212-
const sizeVariantion = props.size && variationName('size', props.size) as keyof typeof styles;
217+
const sizeVariation = props.size && variationName('size', props.size) as keyof typeof styles;
213218
214219
return classNames(
215220
styles.Button,
216221
props.primary && styles.primary,
217222
props.outline && styles.outline,
218-
props.size !== 'medium' && sizeVariantion && styles[sizeVariantion],
219-
textAlignVariantion && styles[textAlignVariantion],
223+
props.size !== 'medium' && sizeVariation && styles[sizeVariation],
224+
textAlignVariation && styles[textAlignVariation],
220225
props.destructive && styles.destructive,
221226
props.connectedDisclosure && props.connectedDisclosure.disabled && styles.disabled,
222227
styles.iconOnly,
@@ -226,9 +231,8 @@ const connectedDisclosureClassName = computed(() => {
226231
});
227232
228233
const commonProps = computed(() => {
229-
const {
230-
id, accessibilityLabel, role, ariaDescribedBy,
231-
} = props;
234+
const { id, accessibilityLabel, role, ariaDescribedBy } = props;
235+
232236
return {
233237
id,
234238
class: className.value,
@@ -241,20 +245,23 @@ const commonProps = computed(() => {
241245
242246
const linkProps = computed(() => {
243247
const { url, external, download } = props;
248+
244249
return { url, external, download };
245250
});
246251
247252
const actionProps = computed(() => {
248253
const { submit, loading, pressed } = props;
254+
249255
return {
250-
submit, loading, pressed, disabled: isDisabled.value,
256+
submit,
257+
loading,
258+
pressed,
259+
disabled: isDisabled.value,
251260
};
252261
});
253262
254263
const buttonMarkupProps = computed(() => {
255-
const {
256-
removeUnderline, disclosure, loading, icon,
257-
} = props;
264+
const { removeUnderline, disclosure, loading, icon } = props;
258265
259266
return {
260267
commonProps: commonProps.value,
@@ -277,6 +284,7 @@ const connectedDisclosureData = computed(() => {
277284
278285
return { disabled, disclosureLabel };
279286
}
287+
280288
return {};
281289
});
282290
@@ -285,6 +293,14 @@ const toggleDisclosureActive = () => {
285293
};
286294
287295
const handleClick = useDisableClick(connectedDisclosureData.value.disabled, toggleDisclosureActive);
296+
297+
const generateUpdateKey = (prefix?: string): string => {
298+
return `${prefix}-${getRandomInt(MAX_RANDOM_NUMBER)}-${isDisabled.value}`;
299+
}
300+
301+
function getRandomInt(max: number): number {
302+
return Math.floor(Math.random() * max);
303+
}
288304
</script>
289305

290306
<style lang="scss">

src/components/Button/ButtonFrom.vue

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,19 @@ const props = withDefaults(defineProps<Props>(), {
2727
overrides: () => ({}),
2828
});
2929
30-
const handleClick = () => {
31-
if (props.action && props.action.onAction) {
32-
props.action.onAction();
33-
}
34-
};
35-
3630
const bindProps = computed(() => {
3731
if (!props.action) {
3832
return {};
3933
}
34+
4035
const { onAction, content, ...other } = props.action;
36+
4137
return { ...other, ...props.overrides };
4238
});
39+
40+
const handleClick = () => {
41+
if (props.action && props.action.onAction) {
42+
props.action.onAction();
43+
}
44+
};
4345
</script>

src/components/Button/ButtonMarkup.vue

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ UnstyledButton(
1616
Icon(:source="loading ? 'placeholder': icon")
1717
span(
1818
v-if="children",
19-
:class="childrenClass",
2019
:key="actionProps && actionProps.disabled ? 'text-disabled' : 'text'",
20+
:class="childrenClass",
2121
)
2222
slot
2323
span(
@@ -68,12 +68,15 @@ const attrs = useAttrs();
6868
const listeners = computed(() => {
6969
const events = ['blur', 'click', 'focus', 'keydown', 'keypress', 'keyup', 'mouseover', 'touchstart', 'pointerdown'];
7070
const eventBindings: Record<string, unknown> = {};
71+
7172
for (const event of events) {
7273
const eventName = `on${capitalize(event)}`;
74+
7375
if (attrs[eventName]) {
7476
eventBindings[event] = attrs[eventName];
7577
}
7678
}
79+
7780
return eventBindings;
7881
});
7982

src/components/Link/Link.vue

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import { classNames } from '@/utilities/css';
3535
import styles from '@/classes/Link.json';
3636
import { UnstyledLink } from '../UnstyledLink';
3737
38-
const props = defineProps<{
38+
interface LinkProps {
3939
/** ID for the link */
4040
id?: string;
4141
/** The url to link to */
@@ -52,7 +52,9 @@ const props = defineProps<{
5252
accessibilityLabel?: string;
5353
/** Indicates whether or not the link is the primary navigation link when rendered inside of an `IndexTable.Row` */
5454
dataPrimaryLink?: boolean;
55-
}>();
55+
}
56+
57+
const props = defineProps<LinkProps>();
5658
5759
const BannerContext = inject('BannerContext', false);
5860

src/components/Link/README.stories.mdx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,13 @@ import { Link } from '@/polaris-vue';
4242
export const Template = (args) => ({
4343
components: { Link },
4444
setup() { return { args }; },
45-
template: `<Link v-bind="args">Fulfilling orders</Link>`,
45+
template: `
46+
<Link v-bind="args">Button</Link>
47+
<br/>
48+
<Link to="path">Router link</Link>
49+
<br/>
50+
<Link href="path">Normal link</Link>
51+
`,
4652
});
4753

4854
# Link
@@ -59,7 +65,9 @@ For actions that aren't related to navigation, use the [button component.](/docs
5965
docs: {
6066
source: {
6167
code: dedent`
62-
<Link>Fulfilling orders</Link>
68+
<Link>Button</Link>
69+
<Link to="path">Router link</Link>
70+
<Link href="path">Normal link</Link>
6371
`,
6472
},
6573
},

src/components/UnstyledLink/UnstyledLink.vue

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
<template lang="pug">
2-
component(
3-
:is="to ? 'router-link' : 'a'",
4-
:href="url",
2+
router-link(
3+
v-if="to",
54
:to="to",
5+
)
6+
slot
7+
a(
8+
v-else,
9+
:href="url",
610
:target="to ? '_blank' : undefined",
711
:rel="external ? 'noopener noreferrer' : undefined",
812
)
@@ -17,5 +21,5 @@ interface Props {
1721
external?: boolean;
1822
}
1923
20-
const props = defineProps<Props>();
24+
defineProps<Props>();
2125
</script>

src/main.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,19 @@
11
import { createApp } from 'vue';
2+
import { createWebHistory, createRouter } from 'vue-router';
23
import Demo from './Demo.vue';
34
import PolarisVue from './polaris-vue';
45

5-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
6-
createApp(Demo as any).use(PolarisVue).mount('#app');
6+
// Define routes for development stage
7+
const routes = [
8+
{ path: '/', component: Demo },
9+
]
10+
11+
const router = createRouter({
12+
history: createWebHistory(),
13+
routes,
14+
});
15+
16+
createApp(Demo)
17+
.use(PolarisVue)
18+
.use(router)
19+
.mount('#app');

0 commit comments

Comments
 (0)