From 9b4879e5044a0c095db9579af5a362ed6b17ebaf Mon Sep 17 00:00:00 2001 From: Gregory Douglas Date: Thu, 21 Nov 2024 18:03:23 -0500 Subject: [PATCH 1/9] Update EditableTextExample --- .../core-examples/editableTextExample.tsx | 181 ++++++++---------- 1 file changed, 80 insertions(+), 101 deletions(-) diff --git a/packages/docs-app/src/examples/core-examples/editableTextExample.tsx b/packages/docs-app/src/examples/core-examples/editableTextExample.tsx index ade67e3272..99a3e8bdf9 100644 --- a/packages/docs-app/src/examples/core-examples/editableTextExample.tsx +++ b/packages/docs-app/src/examples/core-examples/editableTextExample.tsx @@ -1,5 +1,5 @@ /* - * Copyright 2016 Palantir Technologies, Inc. All rights reserved. + * Copyright 2024 Palantir Technologies, Inc. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,109 +23,88 @@ import { IntentSelect } from "./common/intentSelect"; const INPUT_ID = "EditableTextExample-max-length"; -export interface EditableTextExampleState { - alwaysRenderInput?: boolean; - confirmOnEnterKey?: boolean; - disabled?: boolean; - intent?: Intent; - maxLength?: number; - report?: string; - selectAllOnFocus?: boolean; -} +export const EditableTextExample: React.FC = props => { + const [alwaysRenderInput, setAlwaysRenderInput] = React.useState(false); + const [confirmOnEnterKey, setConfirmOnEnterKey] = React.useState(false); + const [disabled, setDisabled] = React.useState(false); + const [intent, setIntent] = React.useState(undefined); + const [maxLength, setMaxLength] = React.useState(undefined); + const [report, setReport] = React.useState(""); + const [selectAllOnFocus, setSelectAllOnFocus] = React.useState(false); -export class EditableTextExample extends React.PureComponent { - public state: EditableTextExampleState = { - alwaysRenderInput: false, - confirmOnEnterKey: false, - disabled: false, - report: "", - selectAllOnFocus: false, - }; + const handleMaxLengthChange = React.useCallback( + (value: number) => { + if (maxLength === 0) { + setMaxLength(undefined); + } else { + setMaxLength(value); + setReport(report.slice(0, value)); + } + }, + [maxLength, report], + ); - private toggleDisabled = handleBooleanChange((disabled: boolean) => this.setState({ disabled })); + const handleReportChange = React.useCallback((value: string) => setReport(value), []); - private handleIntentChange = (intent: Intent) => this.setState({ intent }); - - private toggleSelectAll = handleBooleanChange(selectAllOnFocus => this.setState({ selectAllOnFocus })); - - private toggleSwap = handleBooleanChange(confirmOnEnterKey => this.setState({ confirmOnEnterKey })); - - private toggleAlwaysRenderInput = handleBooleanChange(alwaysRenderInput => this.setState({ alwaysRenderInput })); - - public render() { - return ( - -

- -

- +
Props
+ + + -
- ); - } + + + + + Swap keypress for confirm and newline (multiline only) + + + + ); - private renderOptions() { - return ( - <> -
Props
- - - - - - - - Swap keypress for confirm and newline (multiline only) - - +

+ - - ); - } - - private handleReportChange = (report: string) => this.setState({ report }); - - private handleMaxLengthChange = (maxLength: number) => { - if (maxLength === 0) { - this.setState({ maxLength: undefined }); - } else { - const report = this.state.report.slice(0, maxLength); - this.setState({ maxLength, report }); - } - }; -} +

+ + + ); +}; From f3629fb21fd27b329143e5e34d412073bb6eec26 Mon Sep 17 00:00:00 2001 From: Greg Douglas Date: Thu, 12 Dec 2024 13:59:21 -0500 Subject: [PATCH 2/9] Rewrite EditableText docs --- .../components/editable-text/editable-text.md | 74 +++++++++++-------- .../core-examples/editableTextExamples.tsx | 58 +++++++++++++++ .../src/examples/core-examples/index.ts | 1 + 3 files changed, 104 insertions(+), 29 deletions(-) create mode 100644 packages/docs-app/src/examples/core-examples/editableTextExamples.tsx diff --git a/packages/core/src/components/editable-text/editable-text.md b/packages/core/src/components/editable-text/editable-text.md index 1f593bd14f..67efe0f4fe 100644 --- a/packages/core/src/components/editable-text/editable-text.md +++ b/packages/core/src/components/editable-text/editable-text.md @@ -1,18 +1,34 @@ @# Editable text -__EditableText__ is an interactive component which appears as normal UI text. It transforms into an interactive -text input field when a user hovers and/or focuses on it. +**EditableText** is an interactive component that displays as static text but +visually resembles an input field on hover. When clicked or focused, +it transforms into a text input, allowing for inline text editing. -The text input inherits all font styling from its ancestors, making for a seamless transition between reading and -editing text. +The text input inherits font styling from its parent elements, making for a +seamless transition between reading and editing text. **EditableText** is ideal +for inline renaming, editable descriptions, or simple text updates. You should +not use **EditableText** when a more static, always-editable [**InputGroup**](#core/components/input-group) +or [**TextArea**](#core/components/text-area) component would suffice. -You might use this component for inline renaming, or for an -[editable multiline description](#core/components/editable-text.multiline-mode). -You should not use __EditableText__ when a more static, always-editable -[__InputGroup__](#core/components/input-group) or [__TextArea__](#core/components/text-area) -component would suffice. +@## Import -@reactExample EditableTextExample +```tsx +import { EditableText } from "@blueprintjs/core"; +``` + +@## Usage + +**EditableText** can be used in both controlled and uncontrolled modes, similar +to a standard React [`` element](https://react.dev/reference/react-dom/components/input). +Use the `value` prop for controlled usage, and `defaultValue` for uncontrolled usage. Use `onChange` to listen to +ongoing updates and use `onConfirm` and `onCancel` to listen only to completed or canceled edits. + +The `onConfirm` and `onCancel` callbacks are invoked based on user interaction. The user presses Enter +(or Command + Enter when multiline) or blurs the input to confirm the current value, or presses +Escape to cancel. Canceling resets the field to the last confirmed value. Neither callback is invoked if the +value is unchanged. + +@reactCodeExample EditableTextBasicExample
Centering EditableText
@@ -23,34 +39,34 @@ you should center the component via flexbox or with `position` and `transform: t
- @## Multiline mode -By default, __EditableText__ supports _exactly one line of text_ and will grow or shrink horizontally based on the -length of text. - -You may enable the `multiline` prop to use a `