@teambit/preview.ui.preview-placeholder 0.0.0-15b225c92dfe050f2ec6529de40de2792d15e893

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.
@@ -0,0 +1 @@
1
+ export { PreviewPlaceholder } from './preview-placeholder';
package/dist/index.js ADDED
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PreviewPlaceholder = void 0;
4
+ var preview_placeholder_1 = require("./preview-placeholder");
5
+ Object.defineProperty(exports, "PreviewPlaceholder", { enumerable: true, get: function () { return preview_placeholder_1.PreviewPlaceholder; } });
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":";;;AAAA,6DAA2D;AAAlD,yHAAA,kBAAkB,OAAA"}
@@ -0,0 +1,7 @@
1
+ ;
2
+ ;
3
+
4
+ export const compositions = [];
5
+ export const overview = [];
6
+
7
+ export const compositions_metadata = {"compositions":[]};
@@ -0,0 +1,17 @@
1
+ import React, { ComponentType, ReactNode } from 'react';
2
+ import { Composition } from '@teambit/compositions';
3
+ import { ComponentModel } from '@teambit/component';
4
+ import { ComponentDescriptor } from '@teambit/component-descriptor';
5
+ export declare function getCompositions(component: ComponentDescriptor): Composition[];
6
+ export declare function getDisplayName(component: ComponentDescriptor): string;
7
+ export declare function getDescription(component: ComponentDescriptor): any;
8
+ export declare function PreviewPlaceholder({ component, componentDescriptor, Container, shouldShowPreview, }: {
9
+ component?: ComponentModel;
10
+ componentDescriptor?: ComponentDescriptor;
11
+ Container?: ComponentType<{
12
+ component: any;
13
+ children: ReactNode;
14
+ className: string;
15
+ }>;
16
+ shouldShowPreview?: boolean;
17
+ }): React.JSX.Element;
@@ -0,0 +1,111 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ exports.getCompositions = getCompositions;
30
+ exports.getDisplayName = getDisplayName;
31
+ exports.getDescription = getDescription;
32
+ exports.PreviewPlaceholder = PreviewPlaceholder;
33
+ const react_1 = __importStar(require("react"));
34
+ const compositions_1 = require("@teambit/compositions");
35
+ const design_ui_heading_1 = require("@teambit/design.ui.heading");
36
+ const toolbox_string_capitalize_1 = require("@teambit/toolbox.string.capitalize");
37
+ const base_ui_loaders_skeleton_1 = require("@teambit/base-ui.loaders.skeleton");
38
+ const docs_1 = require("@teambit/docs");
39
+ const preview_placeholder_module_scss_1 = __importDefault(require("./preview-placeholder.module.scss"));
40
+ function getCompositions(component) {
41
+ const entry = component.get(compositions_1.CompositionsAspect.id);
42
+ if (!entry)
43
+ return [];
44
+ const compositions = entry.data.compositions;
45
+ if (!compositions)
46
+ return [];
47
+ return compositions_1.Composition.fromArray(compositions);
48
+ }
49
+ function getDisplayName(component) {
50
+ const tokens = component.id.name.split('-').map((token) => (0, toolbox_string_capitalize_1.capitalize)(token));
51
+ return tokens.join(' ');
52
+ }
53
+ function getDocsProperty(component, name) {
54
+ var _a, _b;
55
+ const docs = ((_a = component.get(docs_1.DocsAspect.id)) === null || _a === void 0 ? void 0 : _a.data) || {};
56
+ if (!docs || !((_b = docs === null || docs === void 0 ? void 0 : docs.doc) === null || _b === void 0 ? void 0 : _b.props))
57
+ return undefined;
58
+ const docProps = docs.doc.props;
59
+ return docProps.find((prop) => prop.name === name);
60
+ }
61
+ function getDescription(component) {
62
+ const descriptionItem = getDocsProperty(component, 'description');
63
+ if (!descriptionItem)
64
+ return '';
65
+ return descriptionItem.value || '';
66
+ }
67
+ function PreviewPlaceholder(_a) {
68
+ var _b, _c;
69
+ var { component, componentDescriptor, Container = ({ children, className }) => react_1.default.createElement("div", { className: className }, children), shouldShowPreview = ((_b = component === null || component === void 0 ? void 0 : component.compositions.length) !== null && _b !== void 0 ? _b : 0) > 0 && (component === null || component === void 0 ? void 0 : component.buildStatus) !== 'pending', } = _a;
70
+ const compositions = component === null || component === void 0 ? void 0 : component.compositions;
71
+ const description = componentDescriptor && getDescription(componentDescriptor);
72
+ const displayName = componentDescriptor && getDisplayName(componentDescriptor);
73
+ const serverUrl = (_c = component === null || component === void 0 ? void 0 : component.server) === null || _c === void 0 ? void 0 : _c.url;
74
+ const prevServerUrlRef = (0, react_1.useRef)(serverUrl);
75
+ const [forceRender, setForceRender] = react_1.default.useState(0);
76
+ (0, react_1.useEffect)(() => {
77
+ if (prevServerUrlRef.current !== serverUrl && shouldShowPreview) {
78
+ prevServerUrlRef.current = serverUrl;
79
+ setForceRender((prev) => prev + 1);
80
+ }
81
+ }, [serverUrl, shouldShowPreview]);
82
+ const selectedPreview = (0, react_1.useMemo)(() => {
83
+ if (!shouldShowPreview || !component)
84
+ return undefined;
85
+ return selectDefaultComposition(component);
86
+ }, [component, shouldShowPreview, forceRender]);
87
+ if (!component || !componentDescriptor)
88
+ return null;
89
+ if (!shouldShowPreview || !compositions || !compositions.length) {
90
+ return (react_1.default.createElement(Container, { className: preview_placeholder_module_scss_1.default.noPreview, component: component },
91
+ react_1.default.createElement("div", { className: preview_placeholder_module_scss_1.default.scope },
92
+ react_1.default.createElement(design_ui_heading_1.H5, { className: preview_placeholder_module_scss_1.default.scopeTitle }, component.id.scope)),
93
+ react_1.default.createElement("div", { className: preview_placeholder_module_scss_1.default.component },
94
+ react_1.default.createElement(design_ui_heading_1.H3, { className: preview_placeholder_module_scss_1.default.componentTitle }, displayName),
95
+ react_1.default.createElement("span", { className: preview_placeholder_module_scss_1.default.description }, description))));
96
+ }
97
+ const name = component.id.toString();
98
+ if (!serverUrl || (!shouldShowPreview && component.buildStatus === 'pending'))
99
+ return (react_1.default.createElement("div", { className: preview_placeholder_module_scss_1.default.previewPlaceholder, "data-tip": "", "data-for": name },
100
+ react_1.default.createElement("div", { className: preview_placeholder_module_scss_1.default.skeletonContainer },
101
+ react_1.default.createElement(base_ui_loaders_skeleton_1.BlockSkeleton, { lines: 12, className: preview_placeholder_module_scss_1.default.skeletonBlock }))));
102
+ return (react_1.default.createElement("div", { key: `${name}-${serverUrl}-${forceRender}` },
103
+ react_1.default.createElement(compositions_1.ComponentComposition, { component: component, composition: selectedPreview, pubsub: false, includeEnv: true, loading: 'lazy', viewport: 1280, queryParams: 'disableCta=true' }),
104
+ react_1.default.createElement("div", { className: preview_placeholder_module_scss_1.default.previewOverlay })));
105
+ }
106
+ const PREVIEW_COMPOSITION_SUFFIX = 'Preview';
107
+ function selectDefaultComposition(component) {
108
+ const { compositions } = component;
109
+ return compositions.find((x) => x.identifier.endsWith(PREVIEW_COMPOSITION_SUFFIX));
110
+ }
111
+ //# sourceMappingURL=preview-placeholder.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"preview-placeholder.js","sourceRoot":"","sources":["../preview-placeholder.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAUA,0C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E,cAAW,IAAI;YACnE,uCAAK,SAAS,EAAE,yCAAM,CAAC,iBAAiB;gBACtC,8BAAC,wCAAa,IAAC,KAAK,EAAE,EAAE,EAAE,SAAS,EAAE,yCAAM,CAAC,aAAa,GAAI,CACzD,CACF,CACP,CAAC;IAEJ,OAAO,CACL,uCAAK,GAAG,EAAE,GAAG,IAAI,IAAI,SAAS,IAAI,WAAW,EAAE;QAC7C,8BAAC,mCAAoB,IACnB,SAAS,EAAE,SAAS,EACpB,WAAW,EAAE,eAAe,EAC5B,MAAM,EAAE,KAAK,EACb,UAAU,EAAE,IAAI,EAChB,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,IAAI,EACd,WAAW,EAAE,iBAAiB,GAC9B;QACF,uCAAK,SAAS,EAAE,yCAAM,CAAC,cAAc,GAAI,CACrC,CACP,CAAC;AACJ,CAAC;AAED,MAAM,0BAA0B,GAAG,SAAS,CAAC;AAE7C,SAAS,wBAAwB,CAAC,SAAyB;IACzD,MAAM,EAAE,YAAY,EAAE,GAAG,SAAS,CAAC;IACnC,OAAO,YAAY,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC,QAAQ,CAAC,0BAA0B,CAAC,CAAC,CAAC;AACrF,CAAC"}
@@ -0,0 +1,94 @@
1
+ .previewPlaceholder {
2
+ display: flex;
3
+ flex-direction: column;
4
+ align-items: center;
5
+ justify-content: center;
6
+ height: 100%;
7
+ width: 100%;
8
+ color: #c7c7c7;
9
+ pointer-events: auto;
10
+ > span:first-child {
11
+ font-size: 30px;
12
+ margin-bottom: 14px;
13
+ }
14
+ > div {
15
+ font-size: 13px;
16
+ }
17
+ }
18
+
19
+ .tooltip {
20
+ max-width: 155px;
21
+ text-align: center;
22
+ }
23
+
24
+ .previewIframe {
25
+ width: 100%;
26
+ height: 100%;
27
+ box-sizing: border-box;
28
+ border: none;
29
+ }
30
+
31
+ .preview {
32
+ overflow: hidden;
33
+ }
34
+
35
+ .description {
36
+ margin-top: 10px;
37
+ font-weight: 400;
38
+ font-size: 12px;
39
+ }
40
+
41
+ .noPreview {
42
+ position: relative;
43
+ background-color: var(--surface-color);
44
+ width: 100%;
45
+ padding: 16px;
46
+ display: flex;
47
+ flex-direction: column;
48
+ align-items: flex-start;
49
+ // justify-content: space-evenly;
50
+ margin: 0;
51
+ position: absolute;
52
+ height: 100%;
53
+ }
54
+
55
+ .component {
56
+ width: 90%;
57
+ }
58
+
59
+ .scopeTitle {
60
+ margin: 0;
61
+ padding-bottom: 25px;
62
+ font-weight: 400;
63
+ }
64
+
65
+ .componentTitle {
66
+ font-size: 28px !important;
67
+ margin: 0;
68
+ margin-bottom: 20px;
69
+ }
70
+
71
+ .previewOverlay {
72
+ position: absolute;
73
+ top: 0;
74
+ left: 0;
75
+ width: 100%;
76
+ height: 100%;
77
+ z-index: 100;
78
+ cursor: pointer;
79
+ }
80
+
81
+ .skeletonContainer {
82
+ width: 100%;
83
+ height: 100%;
84
+ position: relative;
85
+ color: var(--skeleton-color, #e0e0e0);
86
+ opacity: 0.7;
87
+ }
88
+
89
+ .skeletonBlock {
90
+ width: 100%;
91
+ height: 100%;
92
+ min-height: 200px;
93
+ display: block;
94
+ }
package/index.ts ADDED
@@ -0,0 +1 @@
1
+ export { PreviewPlaceholder } from './preview-placeholder';
package/package.json ADDED
@@ -0,0 +1,52 @@
1
+ {
2
+ "name": "@teambit/preview.ui.preview-placeholder",
3
+ "version": "0.0.0-15b225c92dfe050f2ec6529de40de2792d15e893",
4
+ "homepage": "https://bit.cloud/teambit/preview/ui/preview-placeholder",
5
+ "main": "dist/index.js",
6
+ "componentId": {
7
+ "scope": "teambit.preview",
8
+ "name": "ui/preview-placeholder",
9
+ "version": "15b225c92dfe050f2ec6529de40de2792d15e893"
10
+ },
11
+ "dependencies": {
12
+ "core-js": "^3.0.0",
13
+ "@teambit/base-ui.loaders.skeleton": "1.0.1",
14
+ "@teambit/design.ui.heading": "1.0.16",
15
+ "@teambit/component-descriptor": "0.0.0-a9e48408a1e6bef7d2675bad59ed815ea6b304b9",
16
+ "@teambit/toolbox.string.capitalize": "0.0.500"
17
+ },
18
+ "devDependencies": {
19
+ "@types/react": "^17.0.8",
20
+ "@types/mocha": "9.1.0",
21
+ "@types/node": "12.20.4",
22
+ "@types/react-dom": "^17.0.5",
23
+ "@types/jest": "^26.0.0",
24
+ "@babel/runtime": "7.20.0",
25
+ "@types/testing-library__jest-dom": "5.9.5"
26
+ },
27
+ "peerDependencies": {
28
+ "react": "^16.8.0 || ^17.0.0",
29
+ "react-dom": "^16.8.0 || ^17.0.0"
30
+ },
31
+ "license": "Apache-2.0",
32
+ "optionalDependencies": {},
33
+ "peerDependenciesMeta": {},
34
+ "private": false,
35
+ "engines": {
36
+ "node": ">=12.22.0"
37
+ },
38
+ "repository": {
39
+ "type": "git",
40
+ "url": "https://github.com/teambit/bit"
41
+ },
42
+ "keywords": [
43
+ "bit",
44
+ "components",
45
+ "collaboration",
46
+ "web",
47
+ "react",
48
+ "react-components",
49
+ "angular",
50
+ "angular-components"
51
+ ]
52
+ }
@@ -0,0 +1,94 @@
1
+ .previewPlaceholder {
2
+ display: flex;
3
+ flex-direction: column;
4
+ align-items: center;
5
+ justify-content: center;
6
+ height: 100%;
7
+ width: 100%;
8
+ color: #c7c7c7;
9
+ pointer-events: auto;
10
+ > span:first-child {
11
+ font-size: 30px;
12
+ margin-bottom: 14px;
13
+ }
14
+ > div {
15
+ font-size: 13px;
16
+ }
17
+ }
18
+
19
+ .tooltip {
20
+ max-width: 155px;
21
+ text-align: center;
22
+ }
23
+
24
+ .previewIframe {
25
+ width: 100%;
26
+ height: 100%;
27
+ box-sizing: border-box;
28
+ border: none;
29
+ }
30
+
31
+ .preview {
32
+ overflow: hidden;
33
+ }
34
+
35
+ .description {
36
+ margin-top: 10px;
37
+ font-weight: 400;
38
+ font-size: 12px;
39
+ }
40
+
41
+ .noPreview {
42
+ position: relative;
43
+ background-color: var(--surface-color);
44
+ width: 100%;
45
+ padding: 16px;
46
+ display: flex;
47
+ flex-direction: column;
48
+ align-items: flex-start;
49
+ // justify-content: space-evenly;
50
+ margin: 0;
51
+ position: absolute;
52
+ height: 100%;
53
+ }
54
+
55
+ .component {
56
+ width: 90%;
57
+ }
58
+
59
+ .scopeTitle {
60
+ margin: 0;
61
+ padding-bottom: 25px;
62
+ font-weight: 400;
63
+ }
64
+
65
+ .componentTitle {
66
+ font-size: 28px !important;
67
+ margin: 0;
68
+ margin-bottom: 20px;
69
+ }
70
+
71
+ .previewOverlay {
72
+ position: absolute;
73
+ top: 0;
74
+ left: 0;
75
+ width: 100%;
76
+ height: 100%;
77
+ z-index: 100;
78
+ cursor: pointer;
79
+ }
80
+
81
+ .skeletonContainer {
82
+ width: 100%;
83
+ height: 100%;
84
+ position: relative;
85
+ color: var(--skeleton-color, #e0e0e0);
86
+ opacity: 0.7;
87
+ }
88
+
89
+ .skeletonBlock {
90
+ width: 100%;
91
+ height: 100%;
92
+ min-height: 200px;
93
+ display: block;
94
+ }
@@ -0,0 +1,116 @@
1
+ import React, { useMemo, useEffect, useRef, ComponentType, ReactNode } from 'react';
2
+ import { CompositionsAspect, ComponentComposition, Composition } from '@teambit/compositions';
3
+ import { H3, H5 } from '@teambit/design.ui.heading';
4
+ import { capitalize } from '@teambit/toolbox.string.capitalize';
5
+ import { ComponentModel } from '@teambit/component';
6
+ import { ComponentDescriptor } from '@teambit/component-descriptor';
7
+ import { BlockSkeleton } from '@teambit/base-ui.loaders.skeleton';
8
+ import { DocsAspect } from '@teambit/docs';
9
+ import styles from './preview-placeholder.module.scss';
10
+
11
+ export function getCompositions(component: ComponentDescriptor) {
12
+ const entry: any = component.get(CompositionsAspect.id);
13
+ if (!entry) return [];
14
+ const compositions = entry.data.compositions;
15
+ if (!compositions) return [];
16
+ return Composition.fromArray(compositions);
17
+ }
18
+
19
+ export function getDisplayName(component: ComponentDescriptor) {
20
+ const tokens = component.id.name.split('-').map((token) => capitalize(token));
21
+ return tokens.join(' ');
22
+ }
23
+
24
+ function getDocsProperty(component: ComponentDescriptor, name: string) {
25
+ const docs = component.get<any>(DocsAspect.id)?.data || {};
26
+ if (!docs || !docs?.doc?.props) return undefined;
27
+ const docProps = docs.doc.props;
28
+ return docProps.find((prop) => prop.name === name);
29
+ }
30
+
31
+ export function getDescription(component: ComponentDescriptor) {
32
+ const descriptionItem = getDocsProperty(component, 'description');
33
+ if (!descriptionItem) return '';
34
+ return descriptionItem.value || '';
35
+ }
36
+
37
+ export function PreviewPlaceholder({
38
+ component,
39
+ componentDescriptor,
40
+ Container = ({ children, className }) => <div className={className}>{children}</div>,
41
+ shouldShowPreview = (component?.compositions.length ?? 0) > 0 && component?.buildStatus !== 'pending',
42
+ }: {
43
+ component?: ComponentModel;
44
+ componentDescriptor?: ComponentDescriptor;
45
+ Container?: ComponentType<{ component: any; children: ReactNode; className: string }>;
46
+ shouldShowPreview?: boolean;
47
+ }) {
48
+ const compositions = component?.compositions;
49
+ const description = componentDescriptor && getDescription(componentDescriptor);
50
+ const displayName = componentDescriptor && getDisplayName(componentDescriptor);
51
+ const serverUrl = component?.server?.url;
52
+
53
+ const prevServerUrlRef = useRef(serverUrl);
54
+ const [forceRender, setForceRender] = React.useState(0);
55
+
56
+ useEffect(() => {
57
+ if (prevServerUrlRef.current !== serverUrl && shouldShowPreview) {
58
+ prevServerUrlRef.current = serverUrl;
59
+ setForceRender((prev) => prev + 1);
60
+ }
61
+ }, [serverUrl, shouldShowPreview]);
62
+
63
+ const selectedPreview = useMemo(() => {
64
+ if (!shouldShowPreview || !component) return undefined;
65
+ return selectDefaultComposition(component);
66
+ }, [component, shouldShowPreview, forceRender]);
67
+
68
+ if (!component || !componentDescriptor) return null;
69
+
70
+ if (!shouldShowPreview || !compositions || !compositions.length) {
71
+ return (
72
+ <Container className={styles.noPreview} component={component}>
73
+ <div className={styles.scope}>
74
+ <H5 className={styles.scopeTitle}>{component.id.scope}</H5>
75
+ </div>
76
+ <div className={styles.component}>
77
+ <H3 className={styles.componentTitle}>{displayName}</H3>
78
+ <span className={styles.description}>{description}</span>
79
+ </div>
80
+ </Container>
81
+ );
82
+ }
83
+
84
+ const name = component.id.toString();
85
+
86
+ if (!serverUrl || (!shouldShowPreview && component.buildStatus === 'pending'))
87
+ return (
88
+ <div className={styles.previewPlaceholder} data-tip="" data-for={name}>
89
+ <div className={styles.skeletonContainer}>
90
+ <BlockSkeleton lines={12} className={styles.skeletonBlock} />
91
+ </div>
92
+ </div>
93
+ );
94
+
95
+ return (
96
+ <div key={`${name}-${serverUrl}-${forceRender}`}>
97
+ <ComponentComposition
98
+ component={component}
99
+ composition={selectedPreview}
100
+ pubsub={false}
101
+ includeEnv={true}
102
+ loading={'lazy'}
103
+ viewport={1280}
104
+ queryParams={'disableCta=true'}
105
+ />
106
+ <div className={styles.previewOverlay} />
107
+ </div>
108
+ );
109
+ }
110
+
111
+ const PREVIEW_COMPOSITION_SUFFIX = 'Preview';
112
+
113
+ function selectDefaultComposition(component: ComponentModel) {
114
+ const { compositions } = component;
115
+ return compositions.find((x) => x.identifier.endsWith(PREVIEW_COMPOSITION_SUFFIX));
116
+ }
@@ -0,0 +1,29 @@
1
+ declare module '*.png' {
2
+ const value: any;
3
+ export = value;
4
+ }
5
+ declare module '*.svg' {
6
+ import type { FunctionComponent, SVGProps } from 'react';
7
+
8
+ export const ReactComponent: FunctionComponent<SVGProps<SVGSVGElement> & { title?: string }>;
9
+ const src: string;
10
+ export default src;
11
+ }
12
+
13
+ // @TODO Gilad
14
+ declare module '*.jpg' {
15
+ const value: any;
16
+ export = value;
17
+ }
18
+ declare module '*.jpeg' {
19
+ const value: any;
20
+ export = value;
21
+ }
22
+ declare module '*.gif' {
23
+ const value: any;
24
+ export = value;
25
+ }
26
+ declare module '*.bmp' {
27
+ const value: any;
28
+ export = value;
29
+ }
@@ -0,0 +1,42 @@
1
+ declare module '*.module.css' {
2
+ const classes: { readonly [key: string]: string };
3
+ export default classes;
4
+ }
5
+ declare module '*.module.scss' {
6
+ const classes: { readonly [key: string]: string };
7
+ export default classes;
8
+ }
9
+ declare module '*.module.sass' {
10
+ const classes: { readonly [key: string]: string };
11
+ export default classes;
12
+ }
13
+
14
+ declare module '*.module.less' {
15
+ const classes: { readonly [key: string]: string };
16
+ export default classes;
17
+ }
18
+
19
+ declare module '*.less' {
20
+ const classes: { readonly [key: string]: string };
21
+ export default classes;
22
+ }
23
+
24
+ declare module '*.css' {
25
+ const classes: { readonly [key: string]: string };
26
+ export default classes;
27
+ }
28
+
29
+ declare module '*.sass' {
30
+ const classes: { readonly [key: string]: string };
31
+ export default classes;
32
+ }
33
+
34
+ declare module '*.scss' {
35
+ const classes: { readonly [key: string]: string };
36
+ export default classes;
37
+ }
38
+
39
+ declare module '*.mdx' {
40
+ const component: any;
41
+ export default component;
42
+ }