« get me outta code hell

generateColorStyleVariables.js « dependencies « content « src - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/content/dependencies/generateColorStyleVariables.js
blob: 5270dbe46f69dacd457855129fab1b478b97ea80 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
export default {
  extraDependencies: ['html', 'getColors'],

  slots: {
    color: {
      validate: v => v.isColor,
    },

    context: {
      validate: v => v.is(
        'any-content',
        'image-box',
        'page-root',
        'image-box',
        'primary-only'),

      default: 'any-content',
    },

    mode: {
      validate: v => v.is('style', 'property-list'),
      default: 'style',
    },
  },

  generate(slots, {getColors}) {
    if (!slots.color) return [];

    const {
      primary,
      dark,
      dim,
      deep,
      deepGhost,
      lightGhost,
      bg,
      bgBlack,
      shadow,
    } = getColors(slots.color);

    let anyContent = [
      `--primary-color: ${primary}`,
      `--dark-color: ${dark}`,
      `--dim-color: ${dim}`,
      `--deep-color: ${deep}`,
      `--deep-ghost-color: ${deepGhost}`,
      `--light-ghost-color: ${lightGhost}`,
      `--bg-color: ${bg}`,
      `--bg-black-color: ${bgBlack}`,
      `--shadow-color: ${shadow}`,
    ];

    let selectedProperties;

    switch (slots.context) {
      case 'any-content':
        selectedProperties = anyContent;
        break;

      case 'image-box':
        selectedProperties = [
          `--primary-color: ${primary}`,
          `--dim-color: ${dim}`,
          `--deep-color: ${deep}`,
          `--bg-black-color: ${bgBlack}`,
        ];
        break;

      case 'page-root':
        selectedProperties = [
          ...anyContent,
          `--page-primary-color: ${primary}`,
        ];
        break;

      case 'primary-only':
        selectedProperties = [
          `--primary-color: ${primary}`,
        ];
        break;
    }

    switch (slots.mode) {
      case 'style':
        return selectedProperties.join('; ');

      case 'property-list':
        return selectedProperties;
    }
  },
};