UNPKG

@i-novus/ui-core

Version:

Базовые UI компоненты

53 lines (52 loc) 1.99 kB
import { jsx as _jsx } from "react/jsx-runtime"; import { createContext, forwardRef, useContext, useMemo } from 'react'; import classNames from 'classnames'; import { useConfigProvider } from '../../core'; export const RowContext = createContext(null); export const useRowContext = () => { const rowContext = useContext(RowContext); if (rowContext === undefined) { throw new Error('useRowContext должен быть использован в рамках <RowContext.Provider>'); } return rowContext; }; export const Row = forwardRef((props, ref) => { const { className, prefix, align, justify, gutter = 0, children } = props; const { getPrefix } = useConfigProvider(); const prefixCls = getPrefix(prefix); const rowContextValue = useMemo(() => { return { gutter }; }, [gutter]); const alignItems = useMemo(() => { if (align) { const alignMap = { top: 'flex-start', center: 'center', bottom: 'flex-end', baseline: 'baseline', }; return alignMap[align]; } return undefined; }, [align]); const justifyContent = useMemo(() => { if (justify) { const justifyMap = { start: 'flex-start', center: 'center', end: 'flex-end', 'space-between': 'space-between', }; return justifyMap[justify]; } return undefined; }, [justify]); return (_jsx(RowContext.Provider, { value: rowContextValue, children: _jsx("div", { ref: ref, className: classNames(`${prefixCls}-row`, className), style: { marginLeft: Number(`-${gutter && gutter / 2}`), marginRight: Number(`-${gutter && gutter / 2}`), rowGap: gutter, alignItems, justifyContent, }, children: children }) })); }); Row.displayName = 'Row';