@controleonline/ui-common 1.2.122 → 1.2.123

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@controleonline/ui-common",
3
- "version": "1.2.122",
3
+ "version": "1.2.123",
4
4
  "author": "ControleOnline",
5
5
  "description": "ControleOnline Common Quasar UI Component",
6
6
  "license": "MIT",
@@ -12,16 +12,18 @@ const SystemErrorToast = ({error}) => {
12
12
 
13
13
  const palette = useMemo(
14
14
  () => ({
15
+ // Theme `negative` is the fallback when the toastDanger* tokens are not defined.
15
16
  toastDangerBackground: themeColors.toastDangerBackground,
16
- toastDangerBorder: themeColors.toastDangerBorder,
17
- toastDangerIcon: themeColors.toastDangerIcon,
18
- toastDangerText: themeColors.toastDangerText,
17
+ toastDangerBorder: themeColors.toastDangerBorder || themeColors.negative,
18
+ toastDangerIcon: themeColors.toastDangerIcon || themeColors.negative,
19
+ toastDangerText: themeColors.toastDangerText || themeColors.negative,
19
20
  }),
20
21
  [
21
22
  themeColors.toastDangerBackground,
22
23
  themeColors.toastDangerBorder,
23
24
  themeColors.toastDangerIcon,
24
25
  themeColors.toastDangerText,
26
+ themeColors.negative,
25
27
  ],
26
28
  );
27
29
 
@@ -1,24 +1,29 @@
1
+ import {getAllStores} from '@store'
2
+
1
3
  const TOAST_STYLE_KEYS = ['pressable', 'view', 'text', 'indicator']
2
4
 
3
5
  const isPlainObject = value =>
4
6
  value && typeof value === 'object' && !Array.isArray(value)
5
7
 
6
- export const TOAST_ERROR_STYLES = {
7
- pressable: {
8
- backgroundColor: '#FFF7F7',
9
- borderColor: '#FECACA',
10
- borderWidth: 1,
11
- },
12
- indicator: {
13
- backgroundColor: '#DC2626',
14
- },
8
+ // Toast accents come from the theme (`negative` / `warning`), never from fixed RGB (#1484).
9
+ const themeColors = () => {
10
+ try {
11
+ return getAllStores()?.theme?.getters?.colors || {}
12
+ } catch (error) {
13
+ return {}
14
+ }
15
15
  }
16
16
 
17
- export const TOAST_WARNING_STYLES = {
18
- indicator: {
19
- backgroundColor: '#e67e22',
20
- },
21
- }
17
+ export const buildErrorToastStyles = (colors = themeColors()) =>
18
+ colors.negative
19
+ ? {
20
+ pressable: {borderColor: colors.negative, borderWidth: 1},
21
+ indicator: {backgroundColor: colors.negative},
22
+ }
23
+ : {}
24
+
25
+ export const buildWarningToastStyles = (colors = themeColors()) =>
26
+ colors.warning ? {indicator: {backgroundColor: colors.warning}} : {}
22
27
 
23
28
  export const mergeToastStyles = (...styleSets) =>
24
29
  styleSets.reduce((mergedStyles, currentStyleSet) => {
@@ -42,12 +47,12 @@ export const mergeToastStyles = (...styleSets) =>
42
47
 
43
48
  export const withErrorToastStyles = (options = {}) => ({
44
49
  ...options,
45
- styles: mergeToastStyles(TOAST_ERROR_STYLES, options?.styles),
50
+ styles: mergeToastStyles(buildErrorToastStyles(), options?.styles),
46
51
  })
47
52
 
48
53
  export const withWarningToastStyles = (options = {}) => ({
49
54
  ...options,
50
- styles: mergeToastStyles(TOAST_WARNING_STYLES, options?.styles),
55
+ styles: mergeToastStyles(buildWarningToastStyles(), options?.styles),
51
56
  })
52
57
 
53
58
  export default withErrorToastStyles
@@ -1,23 +1,28 @@
1
1
  const {describe, expect, it} = global
2
2
 
3
+ jest.mock('@store', () => ({
4
+ getAllStores: () => ({theme: {getters: {colors: {negative: '#C10015', warning: '#F2C037'}}}}),
5
+ }), {virtual: true})
6
+
3
7
  const {
4
- TOAST_ERROR_STYLES,
5
- TOAST_WARNING_STYLES,
8
+ buildErrorToastStyles,
9
+ buildWarningToastStyles,
6
10
  mergeToastStyles,
7
11
  withErrorToastStyles,
8
12
  withWarningToastStyles,
9
13
  } = require('../../../react/utils/toastPresentation')
10
14
 
11
15
  describe('toastPresentation', () => {
12
- it('keeps the shared error toast on a light, high-contrast panel', () => {
13
- expect(TOAST_ERROR_STYLES.pressable).toMatchObject({
14
- backgroundColor: '#FFF7F7',
15
- borderColor: '#FECACA',
16
- borderWidth: 1,
16
+ it('derives toast accents from the theme negative/warning variables, no fixed RGB (#1484)', () => {
17
+ expect(buildErrorToastStyles({negative: '#C10015'})).toEqual({
18
+ pressable: {borderColor: '#C10015', borderWidth: 1},
19
+ indicator: {backgroundColor: '#C10015'},
17
20
  })
18
- expect(TOAST_ERROR_STYLES.indicator).toMatchObject({
19
- backgroundColor: '#DC2626',
21
+ expect(buildWarningToastStyles({warning: '#F2C037'})).toEqual({
22
+ indicator: {backgroundColor: '#F2C037'},
20
23
  })
24
+ expect(buildErrorToastStyles({})).toEqual({})
25
+ expect(buildWarningToastStyles({})).toEqual({})
21
26
  })
22
27
 
23
28
  it('merges toast style groups without dropping prior sections', () => {
@@ -46,17 +51,16 @@ describe('toastPresentation', () => {
46
51
  })
47
52
  })
48
53
 
49
- it('decorates error and warning toast options with the shared styles', () => {
54
+ it('decorates error and warning toast options with theme-driven styles', () => {
50
55
  expect(withErrorToastStyles({styles: {pressable: {paddingHorizontal: 8}}})).toEqual({
51
56
  styles: {
52
57
  pressable: {
53
- backgroundColor: '#FFF7F7',
54
- borderColor: '#FECACA',
58
+ borderColor: '#C10015',
55
59
  borderWidth: 1,
56
60
  paddingHorizontal: 8,
57
61
  },
58
62
  indicator: {
59
- backgroundColor: '#DC2626',
63
+ backgroundColor: '#C10015',
60
64
  },
61
65
  },
62
66
  })
@@ -64,7 +68,7 @@ describe('toastPresentation', () => {
64
68
  expect(withWarningToastStyles({styles: {text: {fontWeight: '700'}}})).toEqual({
65
69
  styles: {
66
70
  indicator: {
67
- backgroundColor: TOAST_WARNING_STYLES.indicator.backgroundColor,
71
+ backgroundColor: '#F2C037',
68
72
  },
69
73
  text: {
70
74
  fontWeight: '700',
@@ -0,0 +1,14 @@
1
+ import assert from 'node:assert/strict';
2
+ import test from 'node:test';
3
+ import fs from 'node:fs';
4
+
5
+ const read = name => fs.readFileSync(new URL(name, import.meta.url), 'utf8').replace(/\r\n/g, '\n');
6
+
7
+ test('toast error/warning accents come from theme variables, not fixed RGB (#1484)', () => {
8
+ const presentation = read('../../../react/utils/toastPresentation.js');
9
+ assert.match(presentation, /colors\.negative/);
10
+ assert.match(presentation, /colors\.warning/);
11
+ assert.doesNotMatch(presentation, /#(?:DC2626|FFF7F7|FECACA|e67e22)/i);
12
+ const toast = read('../../../react/components/SystemErrorToast.js');
13
+ assert.match(toast, /themeColors\.toastDangerBorder \|\| themeColors\.negative/);
14
+ });