Skip to content

Commit 26cd404

Browse files
authored
Merge pull request #3 from tildeio/reorg
Re-organize render code for shorter files
2 parents 37b8c79 + 6dd7010 commit 26cd404

File tree

8 files changed

+405
-389
lines changed

8 files changed

+405
-389
lines changed

src/css-classes.ts

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
import { Perk, PerkValue } from './types/data';
2+
3+
/**
4+
* The values listed here are used as CSS classes. See source link for more
5+
* information.
6+
*/
7+
export const CLASSES = {
8+
/**
9+
* The element displayed while the grid is loading.
10+
* Only used in custom-element.
11+
*/
12+
loading: 'epg_loading' as const,
13+
/**
14+
* The element displayed if there is an error while loading the grid/
15+
* Only used in custom-element.
16+
*/
17+
error: 'epg_error' as const,
18+
/** The parent grid element, once loaded with no error */
19+
grid: 'epg_grid' as const,
20+
/**
21+
* If the grid element has this class, the element should be displayed as a
22+
* grid rather than as a list.
23+
*/
24+
displayAsGrid: 'epg_display-as-grid' as const,
25+
/** The grid header rowgroup element */
26+
header: 'epg_header' as const,
27+
/** The grid body rowgroup element */
28+
body: 'epg_body' as const,
29+
/** The grid footer rowgroup element */
30+
footer: 'epg_footer' as const,
31+
/** All rowgroup elements */
32+
rowgroup: 'epg_rowgroup' as const,
33+
/** All row elements */
34+
row: 'epg_row' as const,
35+
/** All columnheader elements */
36+
columnheader: 'epg_columnheader' as const,
37+
/** All rowheader elements */
38+
rowheader: 'epg_rowheader' as const,
39+
/** All gridcell, columnheader, and rowheader elements */
40+
cell: 'epg_cell' as const,
41+
/** All gridcell and columnheader elements related to a Package */
42+
package: 'epg_package' as const,
43+
/** All gridcell and rowheader elements related to a Perk */
44+
perk: 'epg_perk' as const,
45+
/** Lists of perks within the package header elements */
46+
packagePerkList: 'epg_package-perk-list' as const,
47+
/** All Package Name or Perk Description elements */
48+
descriptor: 'epg_descriptor' as const,
49+
attributes: {
50+
/** All Package/Park attribute elements */
51+
container: 'epg_attributes' as const,
52+
/** All Package/Park "sold-out" attribute elements */
53+
soldOut: 'epg_attributes-sold-out' as const,
54+
/** All Package/Park "limited" attribute elements */
55+
limited: 'epg_attributes-limited' as const,
56+
},
57+
/**
58+
* @param perk
59+
* @param value A {@link PerkValue} or undefined. If undefined, the value is falsy.
60+
* @returns A string of classes for selecting a perk value.
61+
*
62+
* @example
63+
* ```js
64+
* CLASSES.perkValue(mySimplePerk, false);
65+
* #=> 'epg_perk-value epg_perk-value-simple epg_perk-value-falsy'
66+
*
67+
* CLASSES.perkValue(myQuantityPerk, 1);
68+
* #=> 'epg_perk-value epg_perk-value-quantity epg_perk-value-truthy'
69+
*
70+
* CLASSES.perkValue(myFreeformPerk, undefined);
71+
* #=> 'epg_perk-value epg_perk-value-freeform epg_perk-value-falsy'
72+
* ```
73+
*/
74+
perkValue(perk: Perk, value: PerkValue | undefined): string {
75+
return `epg_perk-value epg_perk-value-${perk.type} epg_perk-value-${
76+
value ? 'truthy' : 'falsy'
77+
}`;
78+
},
79+
};

src/custom-element.ts

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,10 @@
1+
import { CLASSES } from './css-classes';
12
import { fetchData, PerkGridFetchError } from './fetch-data';
2-
import { render, CLASSES as GRID_CLASSES, DisplayOption } from './render';
3+
import { render } from './render';
4+
import { DisplayOption } from './render/types';
35
import { PerkGridTypeError } from './types/utils';
46
import { createElement } from './utils/rendering';
57

6-
/**
7-
* The values listed here are used as CSS classes. See source link for more
8-
* information.
9-
*/
10-
export const CLASSES = {
11-
/** See the './render' file for more details. */
12-
...GRID_CLASSES,
13-
/** The element displayed while the grid is loading */
14-
loading: 'epg_loading' as const,
15-
/** The element displayed if there is an error while loading the grid */
16-
error: 'epg_error' as const,
17-
};
18-
198
/**
209
* The following dataset properties can be set on the `<perk-grid>` element by
2110
* including them as `data-` attributes on the element.
@@ -272,4 +261,4 @@ if (customElements.get('perk-grid')) {
272261
customElements.define('perk-grid', PerkGrid);
273262
}
274263

275-
export {};
264+
export * from './css-classes';

src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import './index.css';
22

3+
export * from './css-classes';
34
export * from './fetch-data';
45
export * from './render';
56
export * from './types/data';

0 commit comments

Comments
 (0)