🚀 Start UI [web] is an opinionated UI starter with 🟦 TypeScript, ⚛️ React, ⚫️ NextJS, ⚡️ Chakra UI, 🟦 tRPC, ▲ Prisma, 🏖️ TanStack Query, 📕 Storybook, 🎭 Playwright,📋 React Hook Form,◽From the 🐻 BearStudio Team
1.36k
stars
127
forks
source link
Code to implement : Editable component #31
Open
FabienEssid opened 3 years ago
I suggest you my whole component : Editable I think we will need to make some adjustments like using Typescript. Here is the entire code :
Editable.js
```jsx import React, { Fragment, useState } from 'react'; import { ButtonGroup, Flex, IconButton, Text, Textarea, } from '@chakra-ui/react'; import PropTypes from 'prop-types'; import { useTranslation } from 'react-i18next'; import { HiCheck, HiPencilAlt, HiX } from 'react-icons/hi'; import TextareaAutosize from 'react-textarea-autosize'; export const Editable = ({ value, onSubmit, onChange, onCancel, isSubmitDisabled, ...rest }) => { const { t } = useTranslation(); const [isEditing, setIsEditing] = useState(false); const [content, setContent] = useState(value); const handleEdit = () => { if (isEditing) { setIsEditing(false); onSubmit(content.trim()); return; } setIsEditing(true); setContent(value); }; const handleCancel = () => { setContent(value); setIsEditing((x) => !x); onCancel(value); }; const handleChange = (e) => { setContent(e.target?.value); onChange(e); }; return (Editable.stories.mdx
```jsx import { Editable } from './Editable'; export default { title: 'components/Editable', component: Editable, }; export const Default = () =>Result example :
https://user-images.githubusercontent.com/50022361/106932147-aaa85780-6717-11eb-8efc-52e68361588f.mp4