• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mia-platform / design-system / 13071907942

31 Jan 2025 11:32AM UTC coverage: 68.605% (-29.3%) from 97.875%
13071907942

Pull #817

github

web-flow
Merge fa7bd8bdd into 174906d3a
Pull Request #817: feat(SplitButton): add onOpenChange prop

123 of 256 branches covered (48.05%)

Branch coverage included in aggregate %.

3 of 3 new or added lines in 1 file covered. (100.0%)

56 existing lines in 12 files now uncovered.

290 of 346 relevant lines covered (83.82%)

4.92 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

18.75
/src/components/ThemeProvider/utils/themeToVariables.ts
1
/**
2
 * Copyright 2023 Mia srl
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *     http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 *
16
 * SPDX-License-Identifier: Apache-2.0
17
 */
18

19
import { isObject } from 'lodash-es'
2✔
20

21
const varsInPixelSegments = ['shape', 'spacing', 'fontSize', 'lineHeight']
2✔
22

23
function addUnitToValue(value: unknown, fieldName: string): unknown {
UNCOV
24
  return varsInPixelSegments.some((segment) => fieldName.includes(segment))
×
25
    ? `${value}px`
26
    : value
27
}
28

29
/**
30
 * Converts a theme configuration into CSS variables.
31
 *
32
 * @param {Theme} theme - The theme configuration to convert.
33
 * @param {string} prefix - Incremental prefix composing the CSS variable names (e.g. -, --palette, --palette-primary).
34
 * @returns {Record<string, string>} A record of CSS variable names and their corresponding values.
35
 */
36
export default function themeToVariables(theme = {}, prefix = '-'): Record<string, string> {
2!
UNCOV
37
  const fields = Object.entries(theme)
×
38

UNCOV
39
  return fields.reduce((variables, [field, value]) => {
×
UNCOV
40
    const fieldName = [prefix, field].join('-')
×
UNCOV
41
    const isNested = isObject(value)
×
42

UNCOV
43
    return {
×
44
      ...variables,
45
      ...isNested
×
46
        ? themeToVariables(value, fieldName)
47
        : { [fieldName]: addUnitToValue(value, fieldName) },
48
    }
49
  }, {})
50
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc