UNPKG

@audira/carbon-react-native

Version:

Build React Native apps with component and shared patterns using Carbon

39 lines (38 loc) 1.23 kB
"use strict"; import { forwardRef, useContext } from 'react'; import { View } from 'react-native'; import { Color } from '@audira/carbon-react-native-elements'; import { MathHelper } from "../../_internal/helpers/index.js"; import { CarbonStyleSheet } from "../../carbon-style-sheet/index.js"; import { LayerContext } from "./LayerContext.js"; import { jsx as _jsx } from "react/jsx-runtime"; export const Layer = /*#__PURE__*/forwardRef(function Layer({ level: levelProp, withBackground, style, ...props }, ref) { const layerContextLevel = useContext(LayerContext), level = levelProp ?? layerContextLevel, value = MathHelper.clamp(level + 1, Color.Layer.MinLevel, Color.Layer.MaxLevel); return /*#__PURE__*/_jsx(LayerContext.Provider, { value: value, children: /*#__PURE__*/_jsx(View, { ref: ref, ...props, style: [withBackground ? bgLevelStyleSheet[value] : undefined, style] }) }); }); const bgLevelStyleSheet = CarbonStyleSheet.create({ 1: { backgroundColor: CarbonStyleSheet.color.layer_01 }, 2: { backgroundColor: CarbonStyleSheet.color.layer_02 }, 3: { backgroundColor: CarbonStyleSheet.color.layer_03 } }); //# sourceMappingURL=Layer.js.map