@bug-on/md3-react 3.0.0 → 3.0.1

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/dist/index.mjs CHANGED
@@ -153,6 +153,11 @@ function MaterialSymbolsPreconnect({
153
153
  )
154
154
  ] });
155
155
  }
156
+ function resolveMode(mode) {
157
+ if (mode !== "system") return mode;
158
+ if (typeof window === "undefined") return "light";
159
+ return window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light";
160
+ }
156
161
  function generateM3Theme(sourceColorHex, mode = "light") {
157
162
  const sourceColor = argbFromHex(sourceColorHex);
158
163
  const theme = themeFromSourceColor(sourceColor);
@@ -211,13 +216,14 @@ function generateM3Theme(sourceColorHex, mode = "light") {
211
216
  };
212
217
  }
213
218
  function applyTheme(sourceColorHex, mode = "light", root = document.documentElement) {
214
- const colors = generateM3Theme(sourceColorHex, mode);
219
+ const resolved = resolveMode(mode);
220
+ const colors = generateM3Theme(sourceColorHex, resolved);
215
221
  for (const [key, value] of Object.entries(colors)) {
216
222
  const kebabKey = key.replace(/[A-Z]/g, (m47) => `-${m47.toLowerCase()}`);
217
223
  root.style.setProperty(`--md-sys-color-${kebabKey}`, value);
218
224
  root.style.setProperty(`--color-m3-${kebabKey}`, value);
219
225
  }
220
- root.setAttribute("data-theme", mode);
226
+ root.setAttribute("data-theme", resolved);
221
227
  }
222
228
  function cn(...inputs) {
223
229
  return twMerge(clsx(inputs));
@@ -1086,6 +1092,11 @@ var SPRING_TRANSITION = {
1086
1092
  bounce: 0,
1087
1093
  duration: 0.3
1088
1094
  };
1095
+ var SPRING_TRANSITION_EXPRESSIVE = {
1096
+ type: "spring",
1097
+ bounce: 0.35,
1098
+ duration: 0.4
1099
+ };
1089
1100
  var ICON_SPAN_VARIANTS = {
1090
1101
  initial: { scale: 0.01 },
1091
1102
  animate: { scale: 1 },
@@ -3926,15 +3937,12 @@ var buttonColorVariants = cva(
3926
3937
  defaultVariants: { colorStyle: "filled" }
3927
3938
  }
3928
3939
  );
3929
- function toSentenceCase(text) {
3930
- return text.charAt(0).toUpperCase() + text.slice(1).toLowerCase();
3931
- }
3932
3940
  function resolveLabel(children, asChild) {
3933
3941
  if (asChild) {
3934
3942
  const child = React38.Children.only(children);
3935
3943
  return child.props.children;
3936
3944
  }
3937
- return typeof children === "string" ? toSentenceCase(children) : children;
3945
+ return children;
3938
3946
  }
3939
3947
  var MOTION_PROP_KEYS = [
3940
3948
  "animate",
@@ -4123,7 +4131,7 @@ var ButtonComponent = React38.forwardRef(
4123
4131
  m.span,
4124
4132
  {
4125
4133
  layout: "size",
4126
- className: "inline-flex items-center gap-[inherit]",
4134
+ className: "inline-flex items-center h-full gap-[inherit]",
4127
4135
  transition: SPRING_TRANSITION,
4128
4136
  children: labelText
4129
4137
  }
@@ -6985,11 +6993,11 @@ function ActivePill({ layoutId, disableInitial = false }) {
6985
6993
  {
6986
6994
  layoutId,
6987
6995
  className: "absolute inset-0 bg-m3-secondary-container pointer-events-none",
6988
- style: { borderRadius: 9999, zIndex: 0 },
6989
- initial: disableInitial ? false : { opacity: 0 },
6990
- animate: { opacity: 1 },
6991
- exit: { opacity: 0 },
6992
- transition: SPRING_TRANSITION
6996
+ style: { borderRadius: 9999, zIndex: 0, originX: 0.5, originY: 0.5 },
6997
+ initial: disableInitial ? false : { opacity: 0, scale: 0.5 },
6998
+ animate: { opacity: 1, scale: 1 },
6999
+ exit: { opacity: 0, scale: 0.5, transition: { duration: 0.15 } },
7000
+ transition: SPRING_TRANSITION_EXPRESSIVE
6993
7001
  }
6994
7002
  );
6995
7003
  }
@@ -13046,7 +13054,8 @@ function MD3ThemeProvider({
13046
13054
  STORAGE_KEY_MODE
13047
13055
  );
13048
13056
  if (savedColor) setSourceColor(savedColor);
13049
- if (savedMode === "light" || savedMode === "dark") setMode(savedMode);
13057
+ if (savedMode === "light" || savedMode === "dark" || savedMode === "system")
13058
+ setMode(savedMode);
13050
13059
  setIsHydrated(true);
13051
13060
  }, [persistToLocalStorage]);
13052
13061
  useEffect(() => {
@@ -13057,9 +13066,17 @@ function MD3ThemeProvider({
13057
13066
  localStorage.setItem(STORAGE_KEY_MODE, mode);
13058
13067
  }
13059
13068
  }, [sourceColor, mode, persistToLocalStorage, isHydrated]);
13069
+ useEffect(() => {
13070
+ if (mode !== "system" || typeof window === "undefined") return;
13071
+ const mediaQuery = window.matchMedia("(prefers-color-scheme: dark)");
13072
+ const handleChange = () => applyTheme(sourceColor, "system");
13073
+ mediaQuery.addEventListener("change", handleChange);
13074
+ return () => mediaQuery.removeEventListener("change", handleChange);
13075
+ }, [mode, sourceColor]);
13076
+ const effectiveMode = resolveMode(mode);
13060
13077
  const themeValue = useMemo(
13061
- () => ({ sourceColor, setSourceColor, mode, setMode }),
13062
- [sourceColor, mode]
13078
+ () => ({ sourceColor, setSourceColor, mode, setMode, effectiveMode }),
13079
+ [sourceColor, mode, effectiveMode]
13063
13080
  );
13064
13081
  const typographyValue = useMemo(() => {
13065
13082
  if (typographyProp) return typographyProp;
@@ -13091,8 +13108,8 @@ function useTheme() {
13091
13108
  return context;
13092
13109
  }
13093
13110
  function useThemeMode() {
13094
- const { mode, setMode } = useTheme();
13095
- return { mode, setMode };
13111
+ const { mode, setMode, effectiveMode } = useTheme();
13112
+ return { mode, setMode, effectiveMode };
13096
13113
  }
13097
13114
  function TableOfContents({
13098
13115
  items,
@@ -13760,6 +13777,6 @@ function TooltipBox({
13760
13777
  ] });
13761
13778
  }
13762
13779
 
13763
- export { APP_BAR_BOTTOM_SPRING, APP_BAR_COLORS, APP_BAR_COLOR_TRANSITION, APP_BAR_ENTER_ALWAYS_SPRING, APP_BAR_TITLE_FADE, AppBarColumn, AppBarOverflowIndicator, AppBarRow, AppBarTokens, Badge, BadgedBox, BottomAppBar, Button, ButtonGroup, CHECK_ICON_VARIANTS, Card, Checkbox, Chip, CodeBlock, ContextMenu, ContextMenuContent, ContextMenuTrigger, DIVIDER_COLOR, DIVIDER_PADDING, Dialog, DialogBody, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogFullScreenContent, DialogHeader, DialogIcon, DialogOverlay, DialogPortal, DialogTitle, DialogTrigger, Divider, DockedToolbar, Drawer, DrawerClose, DrawerContent, DrawerDescription, DrawerFooter, DrawerHeader, DrawerOverlay, DrawerPortal, DrawerTitle, DrawerTrigger, FAB, FABMenu, FABMenuItem, FABPosition, FAST_EFFECTS_TRANSITION, FAST_SPATIAL_SPRING, GROUP_SHAPES, ITEM_SHAPE_CLASSES, Icon, IconButton, LargeFlexibleAppBar, LoadingIndicator, MD3ThemeProvider, MD3_EXPRESSIVE_FONT_VARIATION, MENU_CHECK_ICON_SIZE, MENU_CONTAINER_VARIANTS, MENU_GROUP_GAP, MENU_ICON_SIZE, MENU_ITEM_MIN_HEIGHT, MENU_MAX_WIDTH, MENU_MIN_WIDTH, MaterialSymbolsPreconnect, MediumFlexibleAppBar, Menu, MenuContent, MenuDivider, MenuGroup, MenuItem, MenuProvider, MenuTrigger, NavigationRail, NavigationRailItem, PlainTooltip, ProgressIndicator, RadioButton, RadioGroup, RangeSlider, RichTooltip, Ripple, SEARCH_BAR_EXPAND_SPRING, SEARCH_COLORS, SEARCH_DOCKED_REVEAL_SPRING, SEARCH_FULLSCREEN_SPRING, SEARCH_TYPOGRAPHY, SEARCH_VIEW_SPRING, STANDARD_COLORS, SUBMENU_CONTAINER_VARIANTS, ScrollArea, ScrollAreaScrollbar, Search, SearchAppBar, SearchBar, SearchTokens, SearchView, SearchViewContainer, SearchViewDocked, SearchViewFullScreen, Slider, SliderColors, SliderTokens, SmallAppBar, Snackbar, SnackbarHost, SnackbarProvider, SubMenu, Switch, SwitchColors, SwitchTokens, Tab, TableOfContents, Tabs, TabsColors, TabsContent, TabsList, TabsTokens, Text, TextField, ToggleFAB, TooltipBox, TooltipCaretShape, TooltipTokens, TriStateCheckbox, TypeScaleTokens, Typography, TypographyContext, TypographyKeyTokens, TypographyProvider, TypographyTokens, VIBRANT_COLORS, VerticalMenu, VerticalMenuContent, VerticalMenuDivider, VerticalMenuGroup, appBarTypography, applyTheme, buildWavePath, cn, generateM3Theme, useAppBarScroll, useRipple as useDOMRipple, useMediaQuery, useMenuContext, useRipple2 as useRipple, useRippleState, useSearchKeyboard, useSnackbar, useSnackbarState, useTheme, useThemeMode, useTooltipPosition, useTooltipState, useTypography };
13780
+ export { APP_BAR_BOTTOM_SPRING, APP_BAR_COLORS, APP_BAR_COLOR_TRANSITION, APP_BAR_ENTER_ALWAYS_SPRING, APP_BAR_TITLE_FADE, AppBarColumn, AppBarOverflowIndicator, AppBarRow, AppBarTokens, Badge, BadgedBox, BottomAppBar, Button, ButtonGroup, CHECK_ICON_VARIANTS, Card, Checkbox, Chip, CodeBlock, ContextMenu, ContextMenuContent, ContextMenuTrigger, DIVIDER_COLOR, DIVIDER_PADDING, Dialog, DialogBody, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogFullScreenContent, DialogHeader, DialogIcon, DialogOverlay, DialogPortal, DialogTitle, DialogTrigger, Divider, DockedToolbar, Drawer, DrawerClose, DrawerContent, DrawerDescription, DrawerFooter, DrawerHeader, DrawerOverlay, DrawerPortal, DrawerTitle, DrawerTrigger, FAB, FABMenu, FABMenuItem, FABPosition, FAST_EFFECTS_TRANSITION, FAST_SPATIAL_SPRING, GROUP_SHAPES, ITEM_SHAPE_CLASSES, Icon, IconButton, LargeFlexibleAppBar, LoadingIndicator, MD3ThemeProvider, MD3_EXPRESSIVE_FONT_VARIATION, MENU_CHECK_ICON_SIZE, MENU_CONTAINER_VARIANTS, MENU_GROUP_GAP, MENU_ICON_SIZE, MENU_ITEM_MIN_HEIGHT, MENU_MAX_WIDTH, MENU_MIN_WIDTH, MaterialSymbolsPreconnect, MediumFlexibleAppBar, Menu, MenuContent, MenuDivider, MenuGroup, MenuItem, MenuProvider, MenuTrigger, NavigationRail, NavigationRailItem, PlainTooltip, ProgressIndicator, RadioButton, RadioGroup, RangeSlider, RichTooltip, Ripple, SEARCH_BAR_EXPAND_SPRING, SEARCH_COLORS, SEARCH_DOCKED_REVEAL_SPRING, SEARCH_FULLSCREEN_SPRING, SEARCH_TYPOGRAPHY, SEARCH_VIEW_SPRING, STANDARD_COLORS, SUBMENU_CONTAINER_VARIANTS, ScrollArea, ScrollAreaScrollbar, Search, SearchAppBar, SearchBar, SearchTokens, SearchView, SearchViewContainer, SearchViewDocked, SearchViewFullScreen, Slider, SliderColors, SliderTokens, SmallAppBar, Snackbar, SnackbarHost, SnackbarProvider, SubMenu, Switch, SwitchColors, SwitchTokens, Tab, TableOfContents, Tabs, TabsColors, TabsContent, TabsList, TabsTokens, Text, TextField, ToggleFAB, TooltipBox, TooltipCaretShape, TooltipTokens, TriStateCheckbox, TypeScaleTokens, Typography, TypographyContext, TypographyKeyTokens, TypographyProvider, TypographyTokens, VIBRANT_COLORS, VerticalMenu, VerticalMenuContent, VerticalMenuDivider, VerticalMenuGroup, appBarTypography, applyTheme, buildWavePath, cn, generateM3Theme, resolveMode, useAppBarScroll, useRipple as useDOMRipple, useMediaQuery, useMenuContext, useRipple2 as useRipple, useRippleState, useSearchKeyboard, useSnackbar, useSnackbarState, useTheme, useThemeMode, useTooltipPosition, useTooltipState, useTypography };
13764
13781
  //# sourceMappingURL=index.mjs.map
13765
13782
  //# sourceMappingURL=index.mjs.map