Skip to content

Commit

Permalink
Edit button text, with option to customise text
Browse files Browse the repository at this point in the history
  • Loading branch information
mattheu committed Nov 20, 2024
1 parent ecfcc09 commit c83eb64
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
3 changes: 2 additions & 1 deletion src/components/DateTimeControl/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ The `DateTimeControl` component provides a date and time picker with timezone in

- `label` (string): The label for the date/time control.
- `id` (string): The ID for the base control.
- `onChange` (Function): Callback function to handle date/time change.
- `onChange` (function): Callback function to handle date/time change.
- `value` (string): The current date/time value in UTC format.
- `editButtonText` (string, optional): The text for the edit/set button.

## Usage

Expand Down
16 changes: 12 additions & 4 deletions src/components/DateTimeControl/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,23 @@ import TimeZone from './timezone';
*
* @param {object} props - Component properties.
* @param {string} props.label - The label for the date/time control.
* @param {string} [props.editButtonText] - The text for the edit/set button. (optional)
* @param {string} props.id - The ID for the base control.
* @param {Function} props.onChange - Callback function to handle date/time change.
* @param {string} props.value - The current date/time value in UTC format.
*
* @returns {ReactNode|null} The DateTimeControl component.

Check warning on line 23 in src/components/DateTimeControl/index.js

View workflow job for this annotation

GitHub Actions / ESLint

src/components/DateTimeControl/index.js#L23

The type 'ReactNode' is undefined (jsdoc/no-undefined-types)
*/
function DateTimeControl( { label, id, onChange, value } ) {
function DateTimeControl( {
editButtonText,
label,
id,
onChange,
value,
} ) {
const [ isDatePickerVisible, setIsDatePickerVisible ] = useState( false );
const dateSettings = getDateSettings();
const defaultEditButtonText = value ? __( 'Edit date', 'block-editor-components' ) : __( 'Set date', 'block-editor-components' );

/**
* Convert a date string in the current site local time into a UTC formatted as a MySQL date.
Expand Down Expand Up @@ -63,11 +71,11 @@ function DateTimeControl( { label, id, onChange, value } ) {
) }

<Button
style={ { display: 'block' } }
variant="link"
onClick={ () =>
setIsDatePickerVisible( ! isDatePickerVisible ) }
onClick={ () => setIsDatePickerVisible( ! isDatePickerVisible ) }
>
{ __( 'Edit webinar start time/date', 'block-editor-components' ) }
{ editButtonText ? editButtonText : defaultEditButtonText }
</Button>

{ isDatePickerVisible && (
Expand Down

0 comments on commit c83eb64

Please sign in to comment.