@yandex/ui
Version:
Yandex UI components
33 lines (32 loc) • 1.89 kB
JavaScript
import { __assign, __read, __rest } from "tslib";
import { withBemMod } from '@bem-react/core';
import React, { useState } from 'react';
import { cnTextinput } from '../Textinput';
import { withControl } from '../../withControl/withControl';
import { Label } from '../Label/Textinput-Label';
import './Textinput_view_material.css';
export var withViewMaterial = withBemMod(cnTextinput(), { view: 'material' }, function (WrappedComponent) {
return withControl(function (_a) {
var hint = _a.hint, onChange = _a.onChange, className = _a.className, label = _a.label, variant = _a.variant, focused = _a.focused, addonBefore = _a.addonBefore, props = __rest(_a, ["hint", "onChange", "className", "label", "variant", "focused", "addonBefore"]);
var defaultValue = props.defaultValue, view = props.view, state = props.state;
var _b = __read(useState(defaultValue), 2), value = _b[0], setValue = _b[1];
var floated = Boolean(props.value) || Boolean(value) || focused;
var labeled = Boolean(label);
return (React.createElement(React.Fragment, null,
React.createElement(WrappedComponent, __assign({ className: cnTextinput({
variant: variant,
}, [className]), addonBefore: React.createElement(React.Fragment, null,
addonBefore,
labeled && (React.createElement(Label, { floated: floated }, label))), onChange: function (event) {
setValue(event.target.value);
if (typeof onChange === 'function') {
onChange(event);
}
} }, props)),
hint && (React.createElement("div", { className: cnTextinput('Hint', {
view: view,
state: state,
variant: variant,
}) }, hint))));
});
});