Skip to content

Commit 620142c

Browse files
authored
Merge pull request #147 from ownego/dev
Minor fixes
2 parents 6f3a118 + 5b92a51 commit 620142c

File tree

5 files changed

+56
-48
lines changed

5 files changed

+56
-48
lines changed

src/components/ResourceItem/ResourceItem.vue

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@ li(:class="listItemClassName", :dataHref="dataHref")
3434
)
3535
div(:class="containerClassName", :id="id")
3636
div(
37-
v-if="hasSlot(slots.media) || context.selectable",
37+
v-if="hasSlot(slots.media) || isSelectable",
3838
:class="ownedClassName",
3939
)
4040
div(
41-
v-if="context.selectable",
41+
v-if="isSelectable",
4242
:class="styles.Handle",
4343
@click="handleLargerSelectionArea",
4444
)
@@ -52,7 +52,7 @@ li(:class="listItemClassName", :dataHref="dataHref")
5252
:label="checkboxAccessibilityLabel",
5353
labelHidden,
5454
v-model="selected",
55-
:disabled="context.loading",
55+
:disabled="loading",
5656
)
5757
div(
5858
v-if="hasSlot(slots.media)",
@@ -61,7 +61,7 @@ li(:class="listItemClassName", :dataHref="dataHref")
6161
slot(name="media")
6262
div(v-if="hasSlot(slots.default)", :class="styles.Content")
6363
slot
64-
template(v-if="shortcutActions && !context.loading")
64+
template(v-if="shortcutActions && !loading")
6565
div(
6666
v-if="persistActions",
6767
:class="styles.Actions",
@@ -107,7 +107,7 @@ li(:class="listItemClassName", :dataHref="dataHref")
107107
</template>
108108

109109
<script setup lang="ts">
110-
import { computed, inject, onUpdated, ref, useSlots, watch } from 'vue';
110+
import { computed, inject, ref, useSlots, watch } from 'vue';
111111
import { classNames, variationName } from 'polaris/polaris-react/src/utilities/css';
112112
import { UseI18n } from '@/use';
113113
import { hasSlot } from '@/utilities/has-slot';
@@ -164,24 +164,33 @@ const i18n = UseI18n();
164164
const getUniqueCheckboxID = globalIdGeneratorFactory('ResourceListItemCheckbox');
165165
const getUniqueOverlayID = globalIdGeneratorFactory('ResourceListItemOverlay');
166166
167-
const context = inject('ResourceListContext', {}) as ResourceListContextType;
167+
const {
168+
selectedItems,
169+
selectable,
170+
selectMode,
171+
loading,
172+
resourceName,
173+
onSelectionChange,
174+
} = inject('ResourceListContext', {}) as ResourceListContextType;
168175
169176
const actionsMenuVisible = ref(false);
170177
const focused = ref(false);
171178
const focusedInner = ref(false);
172-
const selected = ref(isSelected(props.id, context.selectedItems?.value));
179+
const selected = ref(isSelected(props.id, selectedItems?.value));
173180
174181
const checkboxId = getUniqueCheckboxID();
175182
const overlayId = getUniqueOverlayID();
176183
const node = ref<HTMLDivElement | null>(null);
177184
const buttonOverlay = ref<HTMLButtonElement | null>(null);
178185
186+
const isSelectable = computed(() => selectable?.value);
187+
179188
const className = computed(() => classNames(
180189
styles.ResourceItem,
181190
focused.value && styles.focused,
182-
context.selectable?.value && styles.selectable,
191+
isSelectable.value && styles.selectable,
183192
selected.value && styles.selected,
184-
context.selectMode?.value && styles.selectMode,
193+
selectMode?.value && styles.selectMode,
185194
props.persistActions && styles.persistActions,
186195
focusedInner.value && styles.focusedInner,
187196
));
@@ -213,17 +222,17 @@ const containerClassName = computed(() => classNames(
213222
styles[variationName('alignment', props.verticalAlignment)],
214223
));
215224
216-
const tabIndex = computed(() => context.loading ? -1 : 0);
225+
const tabIndex = computed(() => loading ? -1 : 0);
217226
218227
const ariaLabel = computed(() => {
219228
return props.accessibilityLabel ||
220229
i18n.translate('Polaris.ResourceList.Item.viewItem', {
221-
itemName: props.name || (context.resourceName && context.resourceName.singular) || '',
230+
itemName: props.name || (resourceName && resourceName.singular) || '',
222231
});
223232
});
224233
225234
watch(
226-
() => context.selectedItems?.value,
235+
() => selectedItems?.value,
227236
(newVal, oldVal) => {
228237
if (newVal !== oldVal) {
229238
selected.value = isSelected(props.id, newVal);
@@ -277,14 +286,14 @@ const handleSelection = (value: boolean, shiftKey: boolean) => {
277286
sortOrder,
278287
} = props;
279288
280-
if (!id || !context.onSelectionChange) {
289+
if (!id || !onSelectionChange) {
281290
return;
282291
}
283292
284293
focused.value = value;
285294
focusedInner.value = value;
286295
287-
context.onSelectionChange(value, id, sortOrder, shiftKey);
296+
onSelectionChange(value, id, sortOrder, shiftKey);
288297
};
289298
290299
const handleClick = (event: MouseEvent) => {
@@ -294,7 +303,7 @@ const handleClick = (event: MouseEvent) => {
294303
const { ctrlKey, metaKey } = event;
295304
const anchor = node.value && node.value.querySelector('a');
296305
297-
if (context.selectMode) {
306+
if (selectMode) {
298307
handleLargerSelectionArea(event);
299308
return;
300309
}
@@ -318,7 +327,7 @@ const handleClick = (event: MouseEvent) => {
318327
const handleKeyUp = (event: KeyboardEvent) => {
319328
const { key } = event;
320329
321-
if (key === 'Enter' && props.url && !context.selectMode) {
330+
if (key === 'Enter' && props.url && !selectMode) {
322331
emits('click', props.id);
323332
}
324333
};
@@ -335,11 +344,11 @@ const stopPropagation = (e: Event) => {
335344
e.stopPropagation();
336345
};
337346
338-
function isSelected(id: string, selectedItems?: ResourceListSelectedItems) {
347+
function isSelected(id: string, tmpSelectedItems?: ResourceListSelectedItems) {
339348
return Boolean(
340-
selectedItems &&
341-
((Array.isArray(selectedItems) && selectedItems.includes(id)) ||
342-
selectedItems === SELECT_ALL_ITEMS),
349+
tmpSelectedItems &&
350+
((Array.isArray(tmpSelectedItems) && tmpSelectedItems.includes(id)) ||
351+
tmpSelectedItems === SELECT_ALL_ITEMS),
343352
);
344353
}
345354
</script>

src/components/ResourceList/ResourceList.vue

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -224,11 +224,13 @@ const defaultResourceName = {
224224
const listRef = ref<HTMLUListElement | null>(null);
225225
const headerRef = ref<HTMLDivElement | null>(null);
226226
227-
const isSelectable = computed(() => Boolean(
228-
(props.promotedBulkActions && props.promotedBulkActions.length > 0) ||
229-
(props.bulkActions && props.bulkActions.length > 0) ||
230-
props.selectable,
231-
));
227+
const isSelectable = computed(() => {
228+
return Boolean(
229+
(props.promotedBulkActions && props.promotedBulkActions.length > 0) ||
230+
(props.bulkActions && props.bulkActions.length > 0) ||
231+
props.selectable,
232+
);
233+
});
232234
233235
const resourceName = computed(() => props.resourceName
234236
? props.resourceName
@@ -650,19 +652,15 @@ const selected = computed<ResourceListSelectedItems>(() => {
650652
return Object.keys(props.selectedItems).map((key) => props.selectedItems[key]);
651653
});
652654
653-
const updateProvider = () => {
654-
provide<ResourceListContextType>('ResourceListContext', {
655-
selectable: isSelectable,
656-
selectedItems: selected,
657-
selectMode: selectMode,
658-
resourceName: props.resourceName,
659-
loading: props.loading,
660-
onSelectionChange: handleSelectionChange,
661-
registerCheckableButtons: handleCheckableButtonRegistration,
662-
});
663-
};
664-
665-
updateProvider();
655+
provide<ResourceListContextType>('ResourceListContext', {
656+
selectable: isSelectable,
657+
selectedItems: selected,
658+
selectMode: selectMode,
659+
resourceName: props.resourceName,
660+
loading: props.loading,
661+
onSelectionChange: handleSelectionChange,
662+
registerCheckableButtons: handleCheckableButtonRegistration,
663+
});
666664
</script>
667665
<style lang="scss">
668666
@import 'polaris/polaris-react/src/components/ResourceList/ResourceList.scss';

src/components/SkeletonPage/README.stories.mdx

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ import { SkeletonPage, Layout, LayoutSection, Card, TextContainer, SkeletonBodyT
55
<Meta
66
title="Components / Feedback indicators / Skeleton page"
77
component={ SkeletonPage }
8-
argTypes={{
9-
}}
108
/>
119

1210
export const Template = (args) => ({
@@ -41,10 +39,10 @@ export const Template = (args) => ({
4139
<SkeletonDisplayText size="small" />
4240
<SkeletonBodyText :lines="2" />
4341
</TextContainer>
44-
</Card.Section>
42+
</CardSection>
4543
<CardSection>
46-
<SkeletonBodyText lines={1} />
47-
</Card.Section>
44+
<SkeletonBodyText :lines="1" />
45+
</CardSection>
4846
</Card>
4947
<Card subdued>
5048
<CardSection>
@@ -100,10 +98,10 @@ Skeleton page is used with other skeleton loading components to provide a low fi
10098
<SkeletonDisplayText size="small" />
10199
<SkeletonBodyText :lines="2" />
102100
</TextContainer>
103-
</Card.Section>
101+
</CardSection>
104102
<CardSection>
105-
<SkeletonBodyText lines={1} />
106-
</Card.Section>
103+
<SkeletonBodyText :lines="1" />
104+
</CardSection>
107105
</Card>
108106
<Card subdued>
109107
<CardSection>

src/utilities/resource-list/context.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export interface ResourceListContextType {
99
button: CheckboxHandles,
1010
): void;
1111
selectMode?: Ref<boolean>;
12-
selectable?: Ref<boolean>;
12+
selectable?: ComputedRef<boolean>;
1313
selectedItems?: ComputedRef<ResourceListSelectedItems>;
1414
resourceName?: {
1515
singular: string;

tsconfig.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@
1818
"paths": {
1919
"@/*": ["./src/*"]
2020
},
21-
"types": ["node"],
21+
"types": [
22+
"node",
23+
"vite/client"
24+
],
2225
// "declaration": true,
2326
// "declarationMap": true,
2427
// "declarationDir": "dist/types",

0 commit comments

Comments
 (0)