@grafana/components 0.0.60 → 0.0.62

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.
@@ -64,13 +64,135 @@ const useColorModeChange = ({
64
64
  return colorMode;
65
65
  };
66
66
 
67
- const ColorModeChangeHandler = ({ children, getAppEvents, useTheme2 }) => {
67
+ const LEGACY_THEME_NAMES = [
68
+ "Aubergine",
69
+ "Dark",
70
+ "Debug",
71
+ "Desert bloom",
72
+ "Deuteranopia/Protanopia Dark",
73
+ "Deuteranopia/Protanopia Light",
74
+ "Gilded grove",
75
+ "Gloom",
76
+ "Light",
77
+ "Mars",
78
+ "Matrix",
79
+ "Sapphire dusk",
80
+ "Synthwave",
81
+ "Tritanopia Dark",
82
+ "Tritanopia Light",
83
+ "Tron",
84
+ "Victorian",
85
+ "Zen"
86
+ ];
87
+ const LEGACY_THEME_IDS = [
88
+ "aubergine",
89
+ "debug",
90
+ "default",
91
+ "desertbloom",
92
+ "deuteranopia_protanopia_dark",
93
+ "deuteranopia_protanopia_light",
94
+ "gildedgrove",
95
+ "gloom",
96
+ "mars",
97
+ "matrix",
98
+ "sapphiredusk",
99
+ "synthwave",
100
+ "tritanopia_dark",
101
+ "tritanopia_light",
102
+ "tron",
103
+ "victorian",
104
+ "zen"
105
+ ];
106
+ const THEME_IDS = {
107
+ Aubergine: "aubergine",
108
+ Dark: "default",
109
+ Debug: "debug",
110
+ "Desert bloom": "desertbloom",
111
+ "Deuteranopia/Protanopia Dark": "deuteranopia_protanopia_dark",
112
+ "Deuteranopia/Protanopia Light": "deuteranopia_protanopia_light",
113
+ "Gilded grove": "gildedgrove",
114
+ Gloom: "gloom",
115
+ Light: "default",
116
+ Mars: "mars",
117
+ Matrix: "matrix",
118
+ "Sapphire dusk": "sapphiredusk",
119
+ Synthwave: "synthwave",
120
+ "Tritanopia Dark": "tritanopia_dark",
121
+ "Tritanopia Light": "tritanopia_light",
122
+ Tron: "tron",
123
+ Victorian: "victorian",
124
+ Zen: "zen"
125
+ };
126
+ const ThemeNameContext = React.createContext(void 0);
127
+ const ThemeNameProvider = ({
128
+ children,
129
+ defaultThemeId = "default"
130
+ }) => {
131
+ const [themeId, setThemeId] = React.useState(defaultThemeId);
132
+ React.useEffect(() => {
133
+ document.documentElement.setAttribute("data-theme-name", themeId);
134
+ }, [themeId]);
135
+ return /* @__PURE__ */ jsxRuntime.jsx(ThemeNameContext.Provider, { value: { themeId, setThemeId }, children });
136
+ };
137
+ const useThemeId = () => {
138
+ const context = React.useContext(ThemeNameContext);
139
+ if (context === void 0) {
140
+ throw new Error("useThemeId must be used within a ThemeNameProvider");
141
+ }
142
+ return context;
143
+ };
144
+
145
+ const isLegacyThemeName = (name) => {
146
+ return LEGACY_THEME_NAMES.includes(name);
147
+ };
148
+ const useThemeNameChange = ({
149
+ getAppEvents,
150
+ useTheme2
151
+ }) => {
152
+ const { themeId, setThemeId } = useThemeId();
153
+ const appEvents = getAppEvents();
154
+ const { name } = useTheme2();
155
+ React.useEffect(() => {
156
+ const themeChangedEvent = appEvents.subscribe(
157
+ runtime.ThemeChangedEvent,
158
+ ({ payload }) => {
159
+ if (isLegacyThemeName(payload.name)) {
160
+ setThemeId(THEME_IDS[payload.name]);
161
+ }
162
+ }
163
+ );
164
+ return () => {
165
+ themeChangedEvent.unsubscribe();
166
+ };
167
+ }, [appEvents, setThemeId]);
168
+ React.useEffect(() => {
169
+ if (isLegacyThemeName(name)) {
170
+ setThemeId(THEME_IDS[name]);
171
+ }
172
+ }, [name, setThemeId]);
173
+ return themeId;
174
+ };
175
+
176
+ const ColorModeChangeHandler = ({
177
+ children,
178
+ getAppEvents,
179
+ useTheme2
180
+ }) => {
68
181
  useColorModeChange({ getAppEvents, useTheme2 });
69
182
  return children;
70
183
  };
71
184
 
185
+ const ThemeNameChangeHandler = ({
186
+ children,
187
+ getAppEvents,
188
+ useTheme2
189
+ }) => {
190
+ useThemeNameChange({ getAppEvents, useTheme2 });
191
+ return children;
192
+ };
193
+
72
194
  const ColorMode = ({ children, getAppEvents, useTheme2 }) => {
73
- return /* @__PURE__ */ jsxRuntime.jsx(ColorModeProvider, { children: /* @__PURE__ */ jsxRuntime.jsx(ColorModeChangeHandler, { getAppEvents, useTheme2, children }) });
195
+ return /* @__PURE__ */ jsxRuntime.jsx(ColorModeProvider, { children: /* @__PURE__ */ jsxRuntime.jsx(ThemeNameProvider, { children: /* @__PURE__ */ jsxRuntime.jsx(ColorModeChangeHandler, { getAppEvents, useTheme2, children: /* @__PURE__ */ jsxRuntime.jsx(ThemeNameChangeHandler, { getAppEvents, useTheme2, children }) }) }) });
74
196
  };
75
197
 
76
198
  const ICON_SIZES = {
@@ -27620,6 +27742,8 @@ exports.Keyboard = Keyboard;
27620
27742
  exports.KeyboardMusic = KeyboardMusic;
27621
27743
  exports.KeyboardOff = KeyboardOff;
27622
27744
  exports.Kubernetes = Kubernetes;
27745
+ exports.LEGACY_THEME_IDS = LEGACY_THEME_IDS;
27746
+ exports.LEGACY_THEME_NAMES = LEGACY_THEME_NAMES;
27623
27747
  exports.Lamp = Lamp;
27624
27748
  exports.LampCeiling = LampCeiling;
27625
27749
  exports.LampDesk = LampDesk;
@@ -28342,6 +28466,7 @@ exports.Sword = Sword;
28342
28466
  exports.Swords = Swords;
28343
28467
  exports.SyntheticMonitoring = SyntheticMonitoring;
28344
28468
  exports.Syringe = Syringe;
28469
+ exports.THEME_IDS = THEME_IDS;
28345
28470
  exports.Table = Table;
28346
28471
  exports.Table2 = Table2;
28347
28472
  exports.TableCellsMerge = TableCellsMerge;
@@ -28388,6 +28513,8 @@ exports.TextSelect = TextSelect;
28388
28513
  exports.TextSelection = TextSelection;
28389
28514
  exports.TextWrap = TextWrap;
28390
28515
  exports.Theater = Theater;
28516
+ exports.ThemeNameChangeHandler = ThemeNameChangeHandler;
28517
+ exports.ThemeNameProvider = ThemeNameProvider;
28391
28518
  exports.Thermometer = Thermometer;
28392
28519
  exports.ThermometerSnowflake = ThermometerSnowflake;
28393
28520
  exports.ThermometerSun = ThermometerSun;
@@ -28584,4 +28711,6 @@ exports.iconMetaData = iconMetaData;
28584
28711
  exports.useColorMode = useColorMode;
28585
28712
  exports.useColorModeChange = useColorModeChange;
28586
28713
  exports.usePortal = usePortal;
28714
+ exports.useThemeId = useThemeId;
28715
+ exports.useThemeNameChange = useThemeNameChange;
28587
28716
  //# sourceMappingURL=index.cjs.map