import { KeyboardEvent, useState } from 'react' import { __ } from '@wordpress/i18n' import classNames from 'classnames' import { getPlainTextFromHtml } from '../../../lib/utils' import { IWebba5ServiceCardProps } from './types' export const Webba5ServiceCard = ({ label, meta, priceLabel, description, selected, onSelect, children, }: IWebba5ServiceCardProps) => { const [descriptionOpen, setDescriptionOpen] = useState(false) const descriptionText = description ? getPlainTextFromHtml(description) : '' const hasDescription = descriptionText.length > 0 const toggleDescription = () => setDescriptionOpen((open) => !open) const handleReadMoreKeyDown = ( event: KeyboardEvent ) => { if (event.key !== 'Enter' && event.key !== ' ') { return } event.preventDefault() toggleDescription() } return (
{hasDescription && (
{descriptionOpen ? __('Read less', 'webba-booking-lite') : __('Read more', 'webba-booking-lite')} {descriptionOpen && (
)}
)} {selected && children}
) }