Write the code for this React component: function VisuallyHidden( { text, as: Tag =…
- User
Write the code for this React component: function VisuallyHidden( { text, as: Tag = 'span', noTranslate = false, additionalAttributes = {}, } ) It returns an element text: The innerText of the element Tag: the html tag of the element noTranslate: determines if the element has the attribute data-notranslate="true" additionalAttributes: All other attributes passed into the element
- Assistant
import React from 'react';
function VisuallyHidden({ text, as = 'span', noTranslate = false, additionalAttributes = {} }: { text: string; as?: string; noTranslate?: boolean; additionalAttributes?: Record<string, any>; }) { const attributes = { ...additionalAttributes, style: { position: 'absolute', width: '1px', height: '1px', padding: '0', margin: '0', overflow: 'hidden', clip: 'rect(0, 0, 0, 0)', border: '0', }, };
if (noTranslate) { attributes.style.whiteSpace = 'nowrap'; attributes.style.overflow = 'hidden'; attributes.style.textOverflow = 'ellipsis'; attributes.style.display = 'block'; attributes.style.maxWidth = '100%'; }
return <Tag {...attributes} className="visually-hidden" />; }
export default VisuallyHidden;
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.