pub struct CopyText { /* private fields */ }Expand description
Copies text to the clipboard on click.
The element gets data-vanilla-state="copied" (or "failed") for 2
seconds. A screen reader hears “Copied” (or “Copy failed”). The element
also sends a vanilla:copied (or vanilla:copy-failed) event. The
runtime never copies a password field or a hidden field.
use autumn_plugin_vanilla::CopyText;
use autumn_web::html;
let html = CopyText::selector("#api-key").button(html! { "Copy" });
assert!(html.into_string().contains(r##"data-vanilla-copy="#api-key""##));Implementations§
Source§impl CopyText
impl CopyText
Sourcepub fn selector(selector: impl Into<String>) -> Self
pub fn selector(selector: impl Into<String>) -> Self
Copies the first match of a CSS selector. For an input, textarea
or select, it copies the value. For other elements, the text.
The selector is trusted input. Do not make it from user data.
Sourcepub fn messages(
self,
done: impl Into<String>,
failed: impl Into<String>,
) -> Self
pub fn messages( self, done: impl Into<String>, failed: impl Into<String>, ) -> Self
Sets the screen reader messages. The defaults are “Copied” and “Copy failed”.
Sourcepub fn attributes(&self) -> Attributes
pub fn attributes(&self) -> Attributes
The attributes, in render order.
Renders a <button type="button"> that copies.
Source§impl CopyText
impl CopyText
Sourcepub fn attr(self, name: &'static str, value: impl Into<String>) -> Self
pub fn attr(self, name: &'static str, value: impl Into<String>) -> Self
Adds an extra attribute, for example id, class or
aria-label.
The name must start with an ASCII letter and contain only
ASCII letters, digits, -, _ and :. The builder ignores
(and logs) event handler names (on…), style, type and
data-vanilla… names.
Trait Implementations§
impl Eq for CopyText
impl StructuralPartialEq for CopyText
Auto Trait Implementations§
impl Forget for CopyText
impl Freeze for CopyText
impl RefUnwindSafe for CopyText
impl Send for CopyText
impl Sync for CopyText
impl Unpin for CopyText
impl UnsafeUnpin for CopyText
impl UnwindSafe for CopyText
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<T> Scoped for T
impl<T> Scoped for T
Source§fn scope(ctx: &PolicyContext) -> ScopeQuery<'_, Self>
fn scope(ctx: &PolicyContext) -> ScopeQuery<'_, Self>
ScopeQuery for this type. Resolves the
registered scope at .load() time, not here.