UNPKG

@ozen-ui/kit

Version:

React component library

27 lines (26 loc) 1.6 kB
import { __assign, __rest } from "tslib"; import './File.css'; import React, { useMemo } from 'react'; import { WarningTriangleOutlineIcon } from '@ozen-ui/icons'; import { useThemeProps } from '../../hooks/useThemeProps'; import { cn } from '../../utils/classname'; import { polymorphicComponentWithRef, } from '../../utils/polymorphicComponentWithRef'; import { Loader } from '../Loader'; import { FILE_DEFAULT_COLOR, FILE_DEFAULT_TAG } from './constants'; export var cnFile = cn('File'); export var fileColorVariant = ['main', 'primary']; export var File = polymorphicComponentWithRef(function (inProps, ref) { var props = useThemeProps({ props: inProps, name: 'File' }); var _a = props.as, Tag = _a === void 0 ? FILE_DEFAULT_TAG : _a, _b = props.color, color = _b === void 0 ? FILE_DEFAULT_COLOR : _b, error = props.error, loading = props.loading, className = props.className, children = props.children, other = __rest(props, ["as", "color", "error", "loading", "className", "children"]); var resolvedChildren = useMemo(function () { if (loading) { return React.createElement(Loader, { color: "var(--color-content-disabled)", size: "s" }); } if (error) { return (React.createElement(WarningTriangleOutlineIcon, { color: "var(--color-content-error)", size: "s" })); } return children; }, [children, loading, error]); return (React.createElement(Tag, __assign({ className: cnFile({ error: error, loading: loading, color: color }, [className]) }, other, { ref: ref }), resolvedChildren)); }); File.displayName = 'File';