### Setup and Run Example App (Without Nix)
Source: https://github.com/alioguzhan/react-editext/blob/master/README.md
This sequence of commands navigates into the example application directory, installs its specific dependencies, and starts its development server. After execution, the example app can be accessed via http://localhost:3000.
```bash
cd example
yarn install
yarn start
```
--------------------------------
### Install Dependencies and Start Watch Process (Without Nix)
Source: https://github.com/alioguzhan/react-editext/blob/master/README.md
These commands are used to set up the project without Nix. First, it installs all necessary project dependencies using Yarn. Then, it starts the rollup watch process, which automatically rebuilds the project upon code changes.
```bash
yarn install
yarn start
```
--------------------------------
### Start Development Environment with Nix
Source: https://github.com/alioguzhan/react-editext/blob/master/README.md
This command initiates a pure Nix shell, which sets up a development environment for both the library and the example application. It is designed to provide a consistent and isolated development experience.
```bash
nix-shell --pure
develop
```
--------------------------------
### Install react-editext
Source: https://github.com/alioguzhan/react-editext/blob/master/README.md
Commands to add the react-editext package to your project using npm or yarn.
```bash
npm install --save react-editext
```
```bash
yarn add react-editext
```
--------------------------------
### Implement basic EdiText component
Source: https://github.com/alioguzhan/react-editext/blob/master/README.md
A basic example showing how to import and use the EdiText component within a functional React component, including state management for the edited value.
```jsx
import React, { useState } from 'react';
import EdiText from 'react-editext';
function Example(props) {
const [value, setValue] = useState('What is real? How do you define real?');
const handleSave = (val) => {
console.log('Edited Value -> ', val);
setValue(val);
};
return (
);
}
```
--------------------------------
### Implement basic EdiText component
Source: https://context7.com/alioguzhan/react-editext/llms.txt
Demonstrates the fundamental usage of the EdiText component by binding a state value and handling the save event. This is the simplest implementation to enable inline editing.
```jsx
import React, { useState } from 'react';
import EdiText from 'react-editext';
function BasicExample() {
const [value, setValue] = useState('Click the edit button to modify this text');
const handleSave = (newValue) => {
console.log('Saved value:', newValue);
setValue(newValue);
};
return (
);
}
```
--------------------------------
### Configure various input types
Source: https://context7.com/alioguzhan/react-editext/llms.txt
Shows how to utilize different input types such as textarea, date, email, and number. It demonstrates the use of the inputProps object to pass native HTML attributes to the underlying input elements.
```jsx
import React from 'react';
import EdiText from 'react-editext';
function InputTypesExample() {
const handleSave = (val) => console.log('Saved:', val);
return (
);
}
```
--------------------------------
### Configure Keyboard Shortcuts and Focus Behavior
Source: https://context7.com/alioguzhan/react-editext/llms.txt
Configures keyboard interactions such as saving on Enter or cancelling on Escape. Also demonstrates focus-based triggers like submitOnUnfocus and startEditingOnFocus.
```jsx
import React, { useState } from 'react';
import EdiText from 'react-editext';
function KeyboardShortcutsExample() {
const handleSave = (val) => console.log('Saved:', val);
return (
console.log('Cancelled:', val)}
/>
);
}
```
--------------------------------
### Handle EdiText Lifecycle Events
Source: https://context7.com/alioguzhan/react-editext/llms.txt
Demonstrates the use of onSave, onCancel, and onEditingStart callbacks to track editing lifecycle events. These callbacks receive the current input value and optional inputProps.
```jsx
import React, { useState } from 'react';
import EdiText from 'react-editext';
function EventsExample() {
const [logs, setLogs] = useState([]);
const [value, setValue] = useState('Edit me to see events');
const addLog = (message) => {
setLogs(prev => [...prev, `${new Date().toLocaleTimeString()}: ${message}`]);
};
return (
{
addLog(`SAVED: "${val}" (input name: ${inputProps?.name || 'unnamed'})`);
setValue(val);
}}
onCancel={(val, inputProps) => {
addLog(`CANCELLED: was editing "${val}"`);
}}
onEditingStart={(val, inputProps) => {
addLog(`EDITING STARTED: current value is "${val}"`);
}}
inputProps={{ name: 'myField' }}
/>
Event Log:
{logs.map((log, i) =>
{log}
)}
);
}
```
--------------------------------
### Display Hint Messages in React EdiText
Source: https://context7.com/alioguzhan/react-editext/llms.txt
Demonstrates how to use the `hint` prop in React EdiText to display helper text below the input field. The hint can be a simple string or a custom React node for advanced formatting. This feature enhances user guidance during editing.
```jsx
import React from 'react';
import EdiText from 'react-editext';
function HintExample() {
const handleSave = (val) => console.log('Saved:', val);
return (
{/* Simple text hint */}
{/* Custom styled hint */}
âšī¸ We'll never share your email with anyone
}
/>
{/* Hint with link */}
See our username guidelines
}
/>
);
}
```
--------------------------------
### Configure Hover-based Button Visibility
Source: https://context7.com/alioguzhan/react-editext/llms.txt
Shows how to use the 'showButtonsOnHover' prop to improve UI cleanliness by hiding action buttons until the user interacts with the component. It also demonstrates combining this with 'editOnViewClick' for an improved user experience.
```jsx
import React from 'react';
import EdiText from 'react-editext';
function ShowOnHoverExample() {
return (
console.log('Saved:', val)}
showButtonsOnHover
editOnViewClick
/>
);
}
```
--------------------------------
### Style EdiText using Styled Components
Source: https://context7.com/alioguzhan/react-editext/llms.txt
Demonstrates how to target internal EdiText elements using the 'editext' data attribute. This allows for granular styling of buttons, containers, and inputs within a styled-components wrapper.
```jsx
import React from 'react';
import styled from 'styled-components';
import EdiText from 'react-editext';
const StyledEdiText = styled(EdiText)`
&[editext="main-container"] {
font-family: 'Arial', sans-serif;
}
button[editext="edit-button"] {
background: #3498db;
color: white;
}
`;
function StyledComponentsExample() {
return (
console.log('Saved:', val)}
/>
);
}
```
--------------------------------
### Customize EdiText internal elements with props
Source: https://context7.com/alioguzhan/react-editext/llms.txt
Demonstrates how to inject custom attributes and styles into the input, display, and container elements of the EdiText component using inputProps, viewProps, and containerProps. This allows for seamless integration with existing CSS frameworks or custom design systems.
```jsx
import React, { useState } from 'react';
import EdiText from 'react-editext';
function PropsCustomizationExample() {
const [liveValue, setLiveValue] = useState('Initial value');
const handleSave = (val) => {
console.log('Saved:', val);
setLiveValue(val);
};
return (
);
}
```
--------------------------------
### Style EdiText components with CSS attribute selectors
Source: https://github.com/alioguzhan/react-editext/blob/master/README.md
Demonstrates how to target specific internal elements of the EdiText component using the 'editext' attribute. This allows for granular styling of buttons, containers, and input fields using standard CSS.
```css
button[editext='cancel-button'] {
&:hover {
background: crimson;
color: #fff;
}
}
div[editext='view-container'] {
background: #6293c3;
padding: 15px;
border-radius: 5px;
color: #fff;
}
div[editext='validation-container'] {
color: #d3d3d3;
text-decoration: underline;
}
input,
textarea {
/** or input[editext="input"] {} */
background: #1d2225;
color: #f4c361;
font-weight: bold;
border-radius: 5px;
}
```
--------------------------------
### Manage EdiText state externally
Source: https://context7.com/alioguzhan/react-editext/llms.txt
Shows how to control the editing mode programmatically using the editing prop and how to restrict edit access using the canEdit prop. This is useful for implementing complex validation or external UI triggers.
```jsx
import React, { useState } from 'react';
import EdiText from 'react-editext';
function ControlledEditingExample() {
const [isEditing, setIsEditing] = useState(false);
const [value, setValue] = useState('Controlled editing example');
const [isLocked, setIsLocked] = useState(true);
return (
);
}
```
--------------------------------
### Customize Button Content and Styling
Source: https://context7.com/alioguzhan/react-editext/llms.txt
Shows how to override default button labels, hide icons, apply custom CSS classes, and adjust button alignment within the EdiText component.
```jsx
import React from 'react';
import EdiText from 'react-editext';
function CustomButtonsExample() {
const handleSave = (val) => console.log('Saved:', val);
return (
Cancel}
/>
);
}
```
--------------------------------
### Customize Value Rendering in React EdiText
Source: https://context7.com/alioguzhan/react-editext/llms.txt
Illustrates the use of the `renderValue` prop in React EdiText to transform how values are displayed in view mode. This is useful for formatting data, parsing URLs into clickable links, or truncating long text while maintaining full content on edit.
```jsx
import React from 'react';
import EdiText from 'react-editext';
function RenderValueExample() {
const handleSave = (val) => console.log('Saved:', val);
return (
{/* Parse and render URLs as links */}
{
const urlRegex = /(https?://[^\s]+)/g;
const parts = value.split(urlRegex);
return (
{parts.map((part, i) =>
urlRegex.test(part) ? (
{part}
) : (
part
)
)}
);
}}
/>
{/* Format currency */}
(
${parseFloat(value).toLocaleString('en-US', { minimumFractionDigits: 2 })}
)}
/>
{/* Truncate long text in view mode */}
(
{value.length > 50 ? value.substring(0, 50) + '...' : value}
)}
/>
);
}
```
=== COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.