Skip to content

Commit 6d9bafb

Browse files
committed
Migrate polaris-react to version 9.20.0
1 parent 96bcca0 commit 6d9bafb

File tree

11 files changed

+209
-25
lines changed

11 files changed

+209
-25
lines changed

.storybook/stories/GetStarted.stories.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import { Meta } from '@storybook/addon-docs';
2424

2525
Polaris Vue by Ownego is a component library for [Vue 3](https://vuejs.org/) based on [Shopify Polaris style guide](https://polaris.shopify.com/). We try to keep the package light-weight and easy to use (mostly similar with original Polaris Library).
2626

27-
**Follow Polaris React version:** [9.19.0](https://github.com/Shopify/polaris/releases/tag/%40shopify%2Fpolaris%409.19.0) - Migrated date: *Jun 30th, 2022*.
27+
**Follow Polaris React version:** [9.20.0](https://github.com/Shopify/polaris/releases/tag/%40shopify%2Fpolaris%409.20.0) - Migrated date: *Jul 12th, 2022*.
2828

2929
<a href="https://github.com/ownego/polaris-vue"><img src="https://img.shields.io/badge/github-%23121011.svg?style=for-the-badge&logo=github&logoColor=white" alt="Github"/></a>
3030

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Polaris Vue by Ownego only supports **Vue 3.0+**.
55
Polaris Vue based on [Shopify Polaris style guide](https://polaris.shopify.com/), built especially for Vue 3.
66
We're trying to make it mostly close with Shopify style guide and get a better performance.
77

8-
**Follow Polaris React version:** [9.19.0](https://github.com/Shopify/polaris/releases/tag/%40shopify%2Fpolaris%409.19.0) - Migrated date: *Jun 30th, 2022*.
8+
**Follow Polaris React version:** [9.20.0](https://github.com/Shopify/polaris/releases/tag/%40shopify%2Fpolaris%409.20.0) - Migrated date: *Jul 12th, 2022*.
99

1010
<br/>
1111

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@ownego/polaris-vue",
33
"version": "1.0.0",
4-
"polaris_version": "9.19.0",
4+
"polaris_version": "9.20.0",
55
"description": "Shopify Polaris UI library for Vue 3",
66
"author": {
77
"name": "Ownego Team"
@@ -37,15 +37,15 @@
3737
"remove-trashes": "rimraf dist/index.html dist/favicon.ico dist/images"
3838
},
3939
"dependencies": {
40-
"@shopify/polaris-icons": "^4.23.0",
40+
"@shopify/polaris-icons": "^5.0.0",
4141
"vite-svg-loader": "^3.1.2",
4242
"vue": "^3.2.31",
4343
"vue-router": "^3.1.6"
4444
},
4545
"devDependencies": {
4646
"@babel/core": "^7.17.5",
4747
"@rushstack/eslint-patch": "^1.1.0",
48-
"@shopify/polaris-tokens": "^5.4.0",
48+
"@shopify/polaris-tokens": "^5.5.0",
4949
"@shopify/typescript-configs": "^5.1.0",
5050
"@storybook/addon-a11y": "^6.5.5",
5151
"@storybook/addon-actions": "^6.5.5",

src/components/AppProvider/AppProvider.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { provide, ref, onMounted, watch } from 'vue';
1010
import { debounce } from 'polaris/polaris-react/src/utilities/debounce';
1111
import { ScrollLockManager } from 'polaris/polaris-react/src/utilities/scroll-lock-manager/scroll-lock-manager';
1212
import { UniqueIdFactory, globalIdGeneratorFactory } from 'polaris/polaris-react/src/utilities/unique-id/unique-id-factory';
13-
import { navigationBarCollapsed } from 'polaris/polaris-react/src/utilities/breakpoints';
13+
import { navigationBarCollapsed } from '@/utilities/breakpoints';
1414
import { I18n } from '@/utilities/i18n';
1515
import lang from 'polaris/polaris-react/locales/en.json';
1616
import { EventListener, CustomProperties } from '@/components';

src/components/Button/Button.vue

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,8 @@ interface Props {
148148
* Disclosure button connected right of the button. Toggles a popover action list.
149149
*/
150150
connectedDisclosure?: ConnectedDisclosure;
151+
/** Indicates whether or not the button is the primary navigation link when rendered inside of an `IndexTable.Row` */
152+
dataPrimaryLink?: boolean;
151153
}
152154
153155
const props = withDefaults(defineProps<Props>(), {
@@ -226,7 +228,12 @@ const commonProps = computed(() => {
226228
id, accessibilityLabel, role, ariaDescribedBy,
227229
} = props;
228230
return {
229-
id, class: className.value, accessibilityLabel, role, ariaDescribedBy,
231+
id,
232+
class: className.value,
233+
accessibilityLabel,
234+
role,
235+
ariaDescribedBy,
236+
'data-primary-link': props.dataPrimaryLink,
230237
};
231238
});
232239

src/components/DataTable/components/Cell/Cell.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ template(v-else)
6868
import { ref, computed, useSlots } from 'vue';
6969
import { classNames, variationName } from 'polaris/polaris-react/src/utilities/css';
7070
import { headerCell } from 'polaris/polaris-react/src/components/shared';
71-
import CaretUpMinor from '@icons/CaretUpMinor.svg';
72-
import CaretDownMinor from '@icons/CaretDownMinor.svg';
71+
import SortAscendingMajor from '@icons/SortAscendingMajor.svg';
72+
import SortDescendingMajor from '@icons/SortDescendingMajor.svg';
7373
import { Icon, Tooltip } from '@/components';
7474
import { UseI18n } from '@/use';
7575
import styles from '@/classes/DataTable.json';
@@ -157,7 +157,7 @@ const headerClassName = computed(() => classNames(
157157
158158
const iconClassName = computed(() => classNames(props.sortable && styles.Icon));
159159
const direction = computed(() => props.sorted && props.sortDirection ? props.sortDirection : props.defaultSortDirection);
160-
const source = computed(() => direction.value === 'descending' ? CaretDownMinor : CaretUpMinor);
160+
const source = computed(() => direction.value === 'descending' ? SortDescendingMajor : SortAscendingMajor);
161161
const oppositeDirection = computed(() => props.sortDirection === 'ascending' ? 'descending' : 'ascending');
162162
163163
const sortAccessibilityLabel = computed(() => i18n.translate(

src/components/EmptyState/EmptyState.vue

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@ div(:class="className")
1515
slot
1616
div(v-if="action || secondaryAction", :class="styles.Actions")
1717
Stack(alignment="center", distribution="center", spacing="tight")
18+
ButtonFrom(
19+
v-if="secondaryAction",
20+
:action="secondaryAction",
21+
)
1822
ButtonFrom(
1923
v-if="action",
2024
:action="action",
2125
:overrides="{ primary: true, size: 'medium' }",
2226
)
23-
ButtonFrom(
24-
v-if="secondaryAction",
25-
:action="secondaryAction",
26-
)
2727
div(v-if="hasSlot(slots.footerContent)", :class="styles.FooterContent")
2828
TextContainer
2929
slot(name="footerContent")

src/components/Link/Link.vue

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ UnstyledLink(
77
:class="className",
88
:external="external",
99
:aria-label="accessibilityLabel",
10+
:data-primary-link="dataPrimaryLink",
1011
)
1112
slot
1213
span(
@@ -21,6 +22,7 @@ button(
2122
type="button",
2223
:class="className",
2324
:aria-label="accessibilityLabel",
25+
:data-primary-link="dataPrimaryLink",
2426
@click="$emit('click')",
2527
)
2628
slot
@@ -55,6 +57,8 @@ const props = defineProps<{
5557
removeUnderline?: boolean;
5658
/** Descriptive text to be read to screenreaders */
5759
accessibilityLabel?: string;
60+
/** Indicates whether or not the link is the primary navigation link when rendered inside of an `IndexTable.Row` */
61+
dataPrimaryLink?: boolean;
5862
}>();
5963
6064
const slots = useSlots();

src/utilities/breakpoints.ts

Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
import type {
2+
BreakpointsAlias,
3+
BreakpointsAliasDirection,
4+
BreakpointsTokenGroup,
5+
} from '@shopify/polaris-tokens';
6+
7+
import {
8+
getMediaConditions,
9+
tokens,
10+
} from '@shopify/polaris-tokens';
11+
12+
import {isServer} from 'polaris/polaris-react/src/utilities/target';
13+
14+
const Breakpoints = {
15+
navigationBarCollapsed: '768px',
16+
stackedContent: '1043px',
17+
};
18+
19+
const noWindowMatches: MediaQueryList = {
20+
media: '',
21+
addListener: noop,
22+
removeListener: noop,
23+
matches: false,
24+
onchange: noop,
25+
addEventListener: noop,
26+
removeEventListener: noop,
27+
dispatchEvent: (_: Event) => true,
28+
};
29+
30+
function noop() { return; }
31+
32+
export function navigationBarCollapsed() {
33+
return typeof window === 'undefined'
34+
? noWindowMatches
35+
: window.matchMedia(`(max-width: ${Breakpoints.navigationBarCollapsed})`);
36+
}
37+
38+
export function stackedContent() {
39+
return typeof window === 'undefined'
40+
? noWindowMatches
41+
: window.matchMedia(`(max-width: ${Breakpoints.stackedContent})`);
42+
}
43+
44+
/**
45+
* Directional alias for each Polaris `breakpoints` token.
46+
*
47+
* @example 'smUp' | 'smDown' | 'smOnly' | 'mdUp' | etc.
48+
*/
49+
export type BreakpointsDirectionAlias =
50+
`${BreakpointsAlias}${Capitalize<BreakpointsAliasDirection>}`;
51+
52+
/**
53+
* Match results for each directional Polaris `breakpoints` alias.
54+
*/
55+
type BreakpointsMatches = {
56+
[DirectionAlias in BreakpointsDirectionAlias]: boolean;
57+
};
58+
59+
const breakpointsQueryEntries = getBreakpointsQueryEntries(tokens.breakpoints);
60+
61+
function getMatches(defaults?: UseBreakpointsOptions['defaults']) {
62+
if (!isServer) {
63+
return Object.fromEntries(
64+
breakpointsQueryEntries.map(([directionAlias, query]) => [
65+
directionAlias,
66+
window.matchMedia(query).matches,
67+
]),
68+
) as BreakpointsMatches;
69+
}
70+
71+
if (typeof defaults === 'object' && defaults !== null) {
72+
return Object.fromEntries(
73+
breakpointsQueryEntries.map(([directionAlias]) => [
74+
directionAlias,
75+
defaults[directionAlias] ?? false,
76+
]),
77+
) as BreakpointsMatches;
78+
}
79+
80+
return Object.fromEntries(
81+
breakpointsQueryEntries.map(([directionAlias]) => [
82+
directionAlias,
83+
defaults ?? false,
84+
]),
85+
) as BreakpointsMatches;
86+
}
87+
88+
export interface UseBreakpointsOptions {
89+
/**
90+
* Default values applied during SSR. Accepts a single value to use for each
91+
* breakpoint alias, or an object for configuring select breakpoints.
92+
*
93+
* @default false
94+
*/
95+
defaults:
96+
| boolean
97+
| {
98+
[DirectionAlias in BreakpointsDirectionAlias]?: boolean;
99+
};
100+
}
101+
102+
/**
103+
* Retrieves media query matches for each directional Polaris `breakpoints` alias.
104+
*
105+
* @example
106+
* const {smUp} = useBreakpoints();
107+
* return smUp && 'Hello world';
108+
*
109+
* @example
110+
* const {mdUp} = useBreakpoints({defaults: {mdUp: true}});
111+
* mdUp //=> `true` during SSR
112+
*
113+
* @example
114+
* const breakpoints = useBreakpoints({defaults: true});
115+
* breakpoints //=> All values will be `true` during SSR
116+
*/
117+
// export function useBreakpoints(options?: UseBreakpointsOptions) {
118+
// const [breakpoints, setBreakpoints] = useState(getMatches(options?.defaults));
119+
120+
// useIsomorphicLayoutEffect(() => {
121+
// const mediaQueryLists = breakpointsQueryEntries.map(([_, query]) =>
122+
// window.matchMedia(query),
123+
// );
124+
125+
// const handler = () => setBreakpoints(getMatches());
126+
127+
// mediaQueryLists.forEach((mql) => {
128+
// mql.addEventListener('change', handler);
129+
// });
130+
131+
// return () =>
132+
// mediaQueryLists.forEach((mql) => {
133+
// mql.removeEventListener('change', handler);
134+
// });
135+
// }, []);
136+
137+
// return breakpoints;
138+
// }
139+
140+
/**
141+
* Converts `breakpoints` tokens into directional media query entries.
142+
*
143+
* @example
144+
* const breakpointsQueryEntries = getBreakpointsQueryEntries(breakpoints);
145+
* breakpointsQueryEntries === [
146+
* ['xsUp', '(min-width: ...)'],
147+
* ['xsDown', '(max-width: ...)'],
148+
* ['xsOnly', '(min-width: ...) and (max-width: ...)'],
149+
* ['smUp', '(min-width: ...) and (max-width: ...)'],
150+
* ['mdUp', '(min-width: ...) and (max-width: ...)'],
151+
* // etc.
152+
* ]
153+
*/
154+
export function getBreakpointsQueryEntries(breakpoints: BreakpointsTokenGroup) {
155+
const mediaConditionEntries = Object.entries(getMediaConditions(breakpoints));
156+
157+
return mediaConditionEntries
158+
.map(([breakpointsToken, mediaConditions]) =>
159+
Object.entries(mediaConditions).map(([direction, mediaCondition]) => {
160+
const breakpointsAlias = breakpointsToken.split('-')[1];
161+
162+
// e.g. smUp, smDown, smOnly, etc.
163+
const directionAlias = `${breakpointsAlias}${capitalize(direction)}`;
164+
165+
return [directionAlias, mediaCondition];
166+
}),
167+
)
168+
.flat() as [BreakpointsDirectionAlias, string][];
169+
}
170+
171+
function capitalize(str: string) {
172+
return str.charAt(0).toUpperCase() + str.slice(1);
173+
}

src/utilities/sticky-manager.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { debounce } from 'polaris/polaris-react/src/utilities/debounce';
22
import { tokens } from '@shopify/polaris-tokens';
33
import { dataPolarisTopBar, scrollable } from 'polaris/polaris-react/src/components/shared';
4-
import { stackedContent } from 'polaris/polaris-react/src/utilities/breakpoints';
4+
import { stackedContent } from '@/utilities/breakpoints';
55
import { getRectForNode, Rect } from './geometry';
66

77
interface StickyItem {

0 commit comments

Comments
 (0)