quantumai-design-system
Version:
퀀텀에이아이의 디자인 시스템
52 lines (51 loc) • 3.83 kB
JavaScript
var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) {
if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
return cooked;
};
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
var __rest = (this && this.__rest) || function (s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
t[p[i]] = s[p[i]];
}
return t;
};
import { jsx as _jsx, jsxs as _jsxs } from "@emotion/react/jsx-runtime";
import { forwardRef, useImperativeHandle, useRef, useState } from 'react';
import { restProps } from '../../../utils/styleSet';
import Icons from '../../Base/Icon/Icons';
import { MaterialContainer } from '../Material/styles';
import styled from '@emotion/styled';
import { COLORS, TYPOGRAPHYS_STYLE } from '../../../styles/theme';
var Upload = forwardRef(function (_a, forwardRef) {
var className = _a.className, style = _a.style, placeholder = _a.placeholder, fileName = _a.fileName, _b = _a.width, width = _b === void 0 ? 220 : _b, onFileChange = _a.onFileChange, props = __rest(_a, ["className", "style", "placeholder", "fileName", "width", "onFileChange"]);
var _c = restProps(__assign({ width: width }, props)), styleProps = _c[0], rest = _c[1];
var _d = useState(fileName), name = _d[0], setName = _d[1];
var internalRef = useRef(null);
useImperativeHandle(forwardRef, function () { return internalRef.current; });
var handleFileChange = function (e) {
var _a, _b;
var fileData = (_a = e.target.files) === null || _a === void 0 ? void 0 : _a[0];
setName(fileData === null || fileData === void 0 ? void 0 : fileData.name);
onFileChange === null || onFileChange === void 0 ? void 0 : onFileChange(fileData);
(_b = props.onChange) === null || _b === void 0 ? void 0 : _b.call(props, e);
};
return (_jsxs(Container, __assign({ className: className, variant: "line", size: "s", style: style, onClick: function () { var _a; return (_a = internalRef.current) === null || _a === void 0 ? void 0 : _a.click(); } }, styleProps, { children: [_jsx("input", { type: "text", value: fileName || name, placeholder: placeholder, disabled: true }), _jsx(Icons, { name: "upload" }), _jsx("input", __assign({}, rest, { type: "file", ref: internalRef, onChange: handleFileChange, multiple: false }))] })));
});
export default Upload;
var Container = styled(MaterialContainer)(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n cursor: pointer;\n gap: 5px;\n & > input[type='text'] {\n flex: 1;\n pointer-events: none;\n text-overflow: ellipsis;\n border: none;\n outline: none;\n ", "\n &::placeholder {\n color: ", ";\n }\n }\n & > input[type='file'] {\n display: none;\n }\n"], ["\n cursor: pointer;\n gap: 5px;\n & > input[type='text'] {\n flex: 1;\n pointer-events: none;\n text-overflow: ellipsis;\n border: none;\n outline: none;\n ", "\n &::placeholder {\n color: ", ";\n }\n }\n & > input[type='file'] {\n display: none;\n }\n"])), TYPOGRAPHYS_STYLE.body1, COLORS.grey6);
var templateObject_1;