Skip to content

Commit c2be8f0

Browse files
authored
Merge pull request #134 from ownego/dev
ResourceList & ResourceItem components
2 parents 2a8d7af + 3f47c6f commit c2be8f0

File tree

41 files changed

+2244
-108
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+2244
-108
lines changed

.eslintrc.cjs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,5 +49,12 @@ module.exports = {
4949
allowBlockStart: false,
5050
},
5151
],
52+
'max-len': ['error', {
53+
code: 150,
54+
ignoreTemplateLiterals: true,
55+
ignoreStrings: true,
56+
ignoreComments: true,
57+
ignorePattern: 'd="([\\s\\S]*?)"',
58+
}],
5259
},
5360
};

.storybook/stories/PolarisIcons.stories.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ So you don't have to install any additional packages.
2626

2727
### **Setup:**
2828

29-
You have to use `vite-svg-loader` in your project. See [Icon Component](?path=/docs/components-images-and-icons-icon) for more details.
29+
You have to use `vite-svg-loader` in your project. See [Icon Component](./?path=/docs/components-images-and-icons-icon) for more details.
3030

3131
Config in `vite.config.ts` if you are using `vite` to compile your project:
3232

build/gen-component-declaration.js

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,6 @@ const TYPE_ROOT = process.cwd();
1111
const packageName = '@ownego/polaris-vue';
1212
const fileName = 'volar.d.ts';
1313

14-
const excludeComponents = [];
15-
16-
function exist (path) {
17-
return fs.existsSync(path);
18-
}
19-
2014
function parseComponentsDeclaration (code) {
2115
if (!code) {
2216
return {};
@@ -28,8 +22,12 @@ function parseComponentsDeclaration (code) {
2822
);
2923
}
3024

31-
async function generateComponentsType () {
32-
const mainImports = await fs.readFile(path.resolve(TYPE_ROOT, 'src/components/index.ts'), 'utf-8');
25+
function generateImportString(key) {
26+
return `typeof import('${packageName}')['${key}']`;
27+
}
28+
29+
function generateComponentsType() {
30+
const mainImports = fs.readFileSync(path.resolve(TYPE_ROOT, 'src/components/index.ts'), 'utf-8');
3331

3432
const pattern = /\'\.\/(.*)\'/g;
3533

@@ -39,14 +37,21 @@ async function generateComponentsType () {
3937
const componentList = mainImports.match(pattern).map((i) => i.replace(/[^\w]/g, ''));
4038

4139
componentList.forEach((key) => {
42-
const entry = `typeof import('${packageName}')['${key}']`
43-
if (!excludeComponents.includes(key)) {
44-
components[key] = entry;
40+
const isSubComponentsExist = fs.existsSync(`src/components/${key}/components`);
41+
const getSubComponentsPattern = /\s\w+\s}/g;
42+
43+
if (isSubComponentsExist) {
44+
const subImports = fs.readFileSync(path.resolve(TYPE_ROOT, `src/components/${key}/index.ts`), 'utf-8');
45+
const subComponentList = subImports.match(getSubComponentsPattern).map((i) => i.replace(/}|\s/g, ''));
46+
47+
subComponentList.forEach((subKey) => components[subKey] = generateImportString(subKey));
48+
} else {
49+
components[key] = generateImportString(key);
4550
}
4651
});
4752

48-
const originalContent = exist(path.resolve(TYPE_ROOT, fileName))
49-
? await fs.readFile(path.resolve(TYPE_ROOT, fileName), 'utf-8')
53+
const originalContent = fs.existsSync(path.resolve(TYPE_ROOT, fileName))
54+
? fs.readFileSync(path.resolve(TYPE_ROOT, fileName), 'utf-8')
5055
: '';
5156

5257
const originImports = parseComponentsDeclaration(originalContent);
@@ -63,6 +68,7 @@ async function generateComponentsType () {
6368
}
6469
return `${name}: ${v}`
6570
});
71+
6672
const code = `// Auto generated component declarations
6773
declare module 'vue' {
6874
export interface GlobalComponents {
@@ -72,8 +78,10 @@ declare module 'vue' {
7278
}
7379
export {}
7480
`;
81+
7582
if (code !== originalContent) {
76-
await fs.writeFile(path.resolve(TYPE_ROOT, fileName), code, 'utf-8');
83+
fs.writeFileSync(path.resolve(TYPE_ROOT, fileName), code, 'utf-8');
7784
}
7885
}
79-
generateComponentsType()
86+
87+
generateComponentsType();

src/classes/FullscreenBar.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"FullscreenBar":"Polaris-FullscreenBar","BackAction":"Polaris-FullscreenBar__BackAction"}

src/classes/ResourceItem.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"CheckboxWrapper":"Polaris-ResourceItem__CheckboxWrapper","ResourceItem":"Polaris-ResourceItem","persistActions":"Polaris-ResourceItem--persistActions","Actions":"Polaris-ResourceItem__Actions","ItemWrapper":"Polaris-ResourceItem__ItemWrapper","focusedInner":"Polaris-ResourceItem--focusedInner","focused":"Polaris-ResourceItem--focused","selected":"Polaris-ResourceItem--selected","Link":"Polaris-ResourceItem__Link","Button":"Polaris-ResourceItem__Button","Container":"Polaris-ResourceItem__Container","alignmentLeading":"Polaris-ResourceItem--alignmentLeading","alignmentTrailing":"Polaris-ResourceItem--alignmentTrailing","alignmentCenter":"Polaris-ResourceItem--alignmentCenter","alignmentFill":"Polaris-ResourceItem--alignmentFill","alignmentBaseline":"Polaris-ResourceItem--alignmentBaseline","Owned":"Polaris-ResourceItem__Owned","OwnedNoMedia":"Polaris-ResourceItem__OwnedNoMedia","Handle":"Polaris-ResourceItem__Handle","selectMode":"Polaris-ResourceItem--selectMode","selectable":"Polaris-ResourceItem--selectable","Media":"Polaris-ResourceItem__Media","Content":"Polaris-ResourceItem__Content","Disclosure":"Polaris-ResourceItem__Disclosure","ListItem":"Polaris-ResourceItem__ListItem"}

src/classes/ResourceList.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"FiltersWrapper":"Polaris-ResourceList__FiltersWrapper","ResourceList":"Polaris-ResourceList","HeaderOuterWrapper":"Polaris-ResourceList__HeaderOuterWrapper","HeaderWrapper-disabled":"Polaris-ResourceList__HeaderWrapper--disabled","HeaderWrapper-overlay":"Polaris-ResourceList__HeaderWrapper--overlay","HeaderWrapper":"Polaris-ResourceList__HeaderWrapper","HeaderWrapper-isSticky":"Polaris-ResourceList__HeaderWrapper--isSticky","HeaderContentWrapper":"Polaris-ResourceList__HeaderContentWrapper","HeaderWrapper-inSelectMode":"Polaris-ResourceList__HeaderWrapper--inSelectMode","SortWrapper":"Polaris-ResourceList__SortWrapper","AlternateToolWrapper":"Polaris-ResourceList__AlternateToolWrapper","HeaderWrapper-hasSelect":"Polaris-ResourceList__HeaderWrapper--hasSelect","HeaderWrapper-hasAlternateTool":"Polaris-ResourceList__HeaderWrapper--hasAlternateTool","HeaderWrapper-hasSort":"Polaris-ResourceList__HeaderWrapper--hasSort","HeaderTitleWrapper":"Polaris-ResourceList__HeaderTitleWrapper","BulkActionsWrapper":"Polaris-ResourceList__BulkActionsWrapper","CheckableButtonWrapper":"Polaris-ResourceList__CheckableButtonWrapper","SelectButtonWrapper":"Polaris-ResourceList__SelectButtonWrapper","EmptySearchResultWrapper":"Polaris-ResourceList__EmptySearchResultWrapper","ResourceListWrapper":"Polaris-ResourceList__ResourceListWrapper","ItemWrapper":"Polaris-ResourceList__ItemWrapper","ItemWrapper-isLoading":"Polaris-ResourceList__ItemWrapper--isLoading","SpinnerContainer":"Polaris-ResourceList__SpinnerContainer","LoadingOverlay":"Polaris-ResourceList__LoadingOverlay","DisabledPointerEvents":"Polaris-ResourceList__DisabledPointerEvents","disableTextSelection":"Polaris-ResourceList--disableTextSelection"}

src/components/AppProvider/AppProvider.vue

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import lang from 'polaris/polaris-react/locales/en.json';
1616
import { EventListener, CustomProperties } from '@/components';
1717
import { PortalManager } from '@/utilities/portal-manager';
1818
import { FocusManager } from '@/utilities/focus-manager';
19+
import { StickyManager } from '@/utilities/sticky-manager';
1920
import type { CustomPropertiesProps } from '../CustomProperties/utils';
2021
import { DEFAULT_COLOR_SCHEME } from '../CustomProperties/utils';
2122
@@ -26,6 +27,8 @@ const props = defineProps({
2627
},
2728
});
2829
30+
const stickyManager = new StickyManager();
31+
2932
const scrollLockManager = new ScrollLockManager();
3033
3134
const portalManager = new PortalManager();
@@ -66,12 +69,14 @@ watch(
6669
onMounted(() => {
6770
if (document !== null) {
6871
setBodyStyles();
72+
stickyManager.setContainer(document);
6973
}
7074
});
7175
7276
const i18n = new I18n(lang);
7377
7478
provide('mediaQueryContext', { isNavigationCollapsed: isNavigationCollapsed.value });
79+
provide('stickyManagerContext', stickyManager);
7580
provide('scrollLockManager', scrollLockManager);
7681
provide('portalManager', portalManager);
7782
provide('uniqueIdFactory', uniqueIdFactory.value);

src/components/Avatar/Avatar.vue

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ span(
1717
text-anchor="middle",
1818
) {{ initials }}
1919
Image(
20-
v-if="source && status !== Status.Errored",
20+
v-if="source && status !== 'ERRORED'",
2121
:class="imageClassName",
2222
:source="source",
2323
alt="",
@@ -32,11 +32,9 @@ import { computed, ref } from 'vue';
3232
import { classNames, variationName } from 'polaris/polaris-react/src/utilities/css';
3333
import styles from '@/classes/Avatar.json';
3434
import { styleClass } from './utils';
35-
import { Image } from '../Image';
35+
import { Image } from '@/components';
3636
import type { Size } from './utils';
3737
38-
type Status = 'PENDING' | 'LOADED' | 'ERRORED';
39-
4038
interface Props {
4139
/**
4240
* Size of avatar
@@ -66,7 +64,7 @@ const props = withDefaults(defineProps<Props>(),{
6664
6765
const emit = defineEmits<{ (event: 'error'): void }>();
6866
69-
const status = ref<Status>('PENDING');
67+
const status = ref<'PENDING' | 'LOADED' | 'ERRORED'>('PENDING');
7068
7169
const svgPath = 'M8.28 27.5A14.95 14.95 0 0120 21.8c4.76 0 8.97 2.24 11.72 5.7a14.02 14.02 0 01-8.25 5.91 14.82 14.82 0 01-6.94 0 14.02 14.02 0 01-8.25-5.9zM13.99 12.78a6.02 6.02 0 1112.03 0 6.02 6.02 0 01-12.03 0z';
7270

src/components/BulkActions/BulkActions.vue

Lines changed: 33 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ div(
33
ref="containerNode",
44
v-if="selectMode",
55
)
6-
div(v-if="smallScreen", ref="smallScreenGroupNode")
6+
div(v-if="smallScreen")
77
div(
88
:class="smallScreenGroupClassName",
99
ref="smallScreenGroupNode",
@@ -53,30 +53,30 @@ div(
5353
span(v-if="paginatedSelectAllText && paginatedSelectAllAction", aria-live="polite") {{ paginatedSelectAllText }}
5454
template(v-else) {{ paginatedSelectAllText }}
5555
Button(
56-
v-if="paginatedSelectAllAction",
56+
v-if="paginatedSelectAllAction && paginatedSelectAllAction.onAction",
5757
plain,
5858
:disabled="disabled",
5959
@click="paginatedSelectAllAction.onAction",
6060
) {{ paginatedSelectAllAction.content }}
61-
div(
62-
v-else,
63-
ref="largeScreenGroupNode",
64-
)
61+
62+
div(v-else)
6563
div(
6664
:class="largeScreenGroupClassName",
6765
ref="largeScreenGroupNode",
6866
)
6967
EventListener(event="resize", :handler="handleResize")
7068
div(
7169
:class="styles.ButtonGroupWrapper",
72-
ref="setLargeScreenButtonsNode",
70+
ref="largeScreenButtonsNode",
7371
)
7472
ButtonGroup(
7573
v-if="(promotedActions && numberOfPromotedActionsToRender > 0) || hasActionsPopover",
7674
segmented,
75+
no-item-wrap,
7776
)
78-
CheckableButton(v-bind="checkableButtonProps", @toggle="emits('toggle-all')")
79-
template(
77+
ButtonGroupItem
78+
CheckableButton(v-bind="checkableButtonProps", @toggle-all="emits('toggle-all')")
79+
ButtonGroupItem(
8080
v-if="promotedActions && numberOfPromotedActionsToRender > 0"
8181
v-for="action, index in promotedActions.slice(0, numberOfPromotedActionsToRender)",
8282
:key="index",
@@ -92,64 +92,52 @@ div(
9292
v-bind="action",
9393
:handleMeasurement="handleMeasurement",
9494
)
95-
div(
96-
v-if="hasActionsPopover",
97-
ref="moreActionsNode",
98-
)
99-
Popover(
100-
:active="largeScreenPopoverVisible",
101-
@close="toggleLargeScreenPopover",
102-
)
103-
template(#activator)
104-
BulkActionButton(
105-
disclosure,
106-
:content="activatorLabel",
107-
:disabled="disabled",
108-
:indicator="isNewBadgeInBadgeActions",
109-
@action="toggleLargeScreenPopover",
110-
)
111-
template(#content)
112-
ActionList(
113-
:sections="combinedActions",
114-
@action-any-item="toggleLargeScreenPopover",
115-
)
116-
CheckableButton(v-else, v-bind="checkableButtonProps")
95+
ButtonGroupItem(v-if="hasActionsPopover")
96+
div(ref="moreActionsNode")
97+
Popover(
98+
:active="largeScreenPopoverVisible",
99+
@close="toggleLargeScreenPopover",
100+
)
101+
template(#activator)
102+
BulkActionButton(
103+
disclosure,
104+
:content="activatorLabel",
105+
:disabled="disabled",
106+
:indicator="isNewBadgeInBadgeActions",
107+
@action="toggleLargeScreenPopover",
108+
)
109+
template(#content)
110+
ActionList(
111+
:sections="combinedActions",
112+
@action-any-item="toggleLargeScreenPopover",
113+
)
114+
CheckableButton(v-else, v-bind="checkableButtonProps", @toggle-all="emits('toggle-all')")
117115
div(
118116
v-if="paginatedSelectAllAction",
119117
:class="styles.PaginatedSelectAll"
120118
)
121119
span(v-if="paginatedSelectAllText && paginatedSelectAllAction", aria-live="polite") {{ paginatedSelectAllText }}
122120
template(v-else) {{ paginatedSelectAllText }}
123121
Button(
124-
v-if="paginatedSelectAllAction",
122+
v-if="paginatedSelectAllAction && paginatedSelectAllAction.onAction",
125123
plain,
126124
:disabled="disabled",
127125
@click="paginatedSelectAllAction.onAction",
128126
) {{ paginatedSelectAllAction.content }}
129127
</template>
130128

131129
<script setup lang="ts">
132-
import { ref, computed, onMounted, watch } from 'vue';
130+
import { ref, computed, watch } from 'vue';
133131
import { debounce } from 'polaris/polaris-react/src/utilities/debounce';
134-
import { tokens } from '@shopify/polaris-tokens';
135132
import { classNames } from 'polaris/polaris-react/src/utilities/css';
136133
import { clamp } from 'polaris/polaris-react/src/utilities/clamp';
137134
import type { MenuGroupDescriptor } from '@/components/ActionMenu/components/MenuGroup/utils';
138-
import type { ActionListSection } from '@/components/ActionList/utils';
139135
import type { Action } from '@/utilities/type';
140-
import type { DisableableAction, BadgeAction } from '@/utilities/interface';
141136
import { UseI18n } from '@/use';
142137
import styles from '@/classes/BulkActions.json';
143-
import { ActionList, Popover, Button, ButtonGroup, CheckableButton, EventListener } from '@/components';
138+
import { ActionList, Popover, Button, ButtonGroup, ButtonGroupItem, CheckableButton, EventListener } from '@/components';
144139
import { BulkActionButton, BulkActionMenu } from './components';
145-
146-
type BulkAction = DisableableAction & BadgeAction;
147-
148-
type BulkActionListSection = ActionListSection;
149-
150-
type TransitionStatus = 'entering' | 'entered' | 'exiting' | 'exited';
151-
152-
const MAX_PROMOTED_ACTIONS = 2;
140+
import type { BulkAction, BulkActionListSection } from './utils';
153141
154142
interface BulkActionsProps {
155143
/** Visually hidden text for screen readers */
@@ -250,13 +238,6 @@ const numberOfPromotedActionsToRender = computed<number>(() => {
250238
return clamp(counter, 0, props.promotedActions.length);
251239
});
252240
253-
const hasActions = computed(() => {
254-
return Boolean(
255-
(props.promotedActions && props.promotedActions.length > 0) ||
256-
(props.actions && props.actions.length > 0),
257-
);
258-
});
259-
260241
const actionSectionsHandler = (): BulkActionListSection[] | undefined => {
261242
if (!props.actions || props.actions.length === 0) {
262243
return;
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import type { DisableableAction, BadgeAction } from '@/utilities/interface';
2+
import type { ActionListSection } from '@/components/ActionList/utils';
3+
import type { MenuGroupDescriptor } from '@/components/ActionMenu/components/MenuGroup/utils';
4+
import type { Action } from '@/utilities/type';
5+
6+
export type BulkAction = DisableableAction & BadgeAction;
7+
8+
export type BulkActionListSection = ActionListSection;
9+
10+
export interface BulkActionsProps {
11+
/** Visually hidden text for screen readers */
12+
accessibilityLabel?: string;
13+
/** Whether to render the small screen BulkActions or not */
14+
smallScreen?: boolean;
15+
/** Label for the bulk actions */
16+
label?: string;
17+
/** State of the bulk actions checkbox */
18+
selected?: boolean | 'indeterminate';
19+
/** List is in a selectable state */
20+
selectMode?: boolean;
21+
/** Actions that will be given more prominence */
22+
promotedActions?: (BulkAction | MenuGroupDescriptor)[];
23+
/** List of actions */
24+
actions?: (BulkAction | BulkActionListSection)[];
25+
/** Text to select all across pages */
26+
paginatedSelectAllText?: string;
27+
/** Action for selecting all across pages */
28+
paginatedSelectAllAction?: Action;
29+
/** Disables bulk actions */
30+
disabled?: boolean;
31+
}

0 commit comments

Comments
 (0)