UNPKG

@atlaskit/navigation-system

Version:

The latest navigation system for Atlassian apps.

46 lines (45 loc) • 2.48 kB
import _defineProperty from "@babel/runtime/helpers/defineProperty"; function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; } function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; } import { useMemo } from 'react'; import { useColorMode } from '@atlaskit/app-provider/use-color-mode'; import { getTokenValue } from '@atlaskit/tokens/get-token-value'; import { parseHex } from './color-utils/formats/hex'; import { useCustomTheme } from './use-custom-theme'; function toRGBString(_ref) { var r = _ref.r, g = _ref.g, b = _ref.b; return "rgb(".concat(r, ", ").concat(g, ", ").concat(b, ")"); } /** * React hook that computes the custom theme style for the top navigation bar. * * Determines whether a custom theme is enabled, computes the resulting style, * and checks if the background color matches the default for the current color mode. * * @param theme Optional custom theme configuration object. * @returns An object indicating if the custom theme is enabled, the computed style, * and a flag specifying if the default background color is used. */ export function useCustomThemeNew(theme) { var value = useCustomTheme(theme); /** * We use the color mode to determine the default background color for the top nav. * We need to use the hook because the user could change their color mode preference. */ var colorMode = useColorMode(); var hasDefaultBackground = useMemo(function () { if (!value.isEnabled) { return true; } var defaultBackground = parseHex(getTokenValue('elevation.surface', colorMode === 'light' ? '#FFFFFF' : '#1F1F21')); return defaultBackground ? value.style.backgroundColor === toRGBString(defaultBackground) : true; }, [value, colorMode]); if (value.isEnabled) { return _objectSpread(_objectSpread({}, value), {}, { hasDefaultBackground: hasDefaultBackground }); } return value; }