Enum patternfly_yew::ClipboardVariant
source · pub enum ClipboardVariant {
Default,
Inline,
Expandable,
Expanded,
}Variants§
Implementations§
source§impl ClipboardVariant
impl ClipboardVariant
sourcepub fn is_expandable(&self) -> bool
pub fn is_expandable(&self) -> bool
Examples found in repository?
src/clipboard.rs (line 219)
218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235
fn expander(&self, ctx: &Context<Self>) -> Html {
if !ctx.props().variant.is_expandable() {
return Default::default();
}
let onclick = ctx.link().callback(|_| Msg::ToggleExpand);
return html! {
<Button
expanded={self.expanded}
variant={Variant::Control}
onclick={onclick}>
<div class="pf-c-clipboard-copy__toggle-icon">
{ Icon::AngleRight }
</div>
</Button>
};
}sourcepub fn is_inline(&self) -> bool
pub fn is_inline(&self) -> bool
Examples found in repository?
src/clipboard.rs (line 133)
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295
fn view(&self, ctx: &Context<Self>) -> Html {
let mut classes = Classes::from("pf-c-clipboard-copy");
if self.expanded {
classes.push("pf-m-expanded");
}
if ctx.props().variant.is_inline() {
classes.push("pf-m-inline");
}
let value = self.value(ctx);
html! {
<div class={classes}>
{ match ctx.props().variant {
ClipboardVariant::Inline => {
html!{
<>
if ctx.props().code {
<code name={ctx.props().name.clone()} id={ctx.props().id.clone()} class="pf-c-clipboard-copy__text pf-m-code">{value}</code>
} else {
<span name={ctx.props().name.clone()} id={ctx.props().id.clone()} class="pf-c-clipboard-copy__text">{value}</span>
}
<span class="pf-c-clipboard-copy__actions">
<span class="pf-c-clipboard-copy__actions-item">
<Tooltip text={self.message}>
<Button aria_label="Copy to clipboard" variant={Variant::Plain} icon={Icon::Copy} onclick={ctx.link().callback(|_|Msg::Copy)}/>
</Tooltip>
</span>
</span>
</>
}
},
_ => {
html!{
<>
<div class="pf-c-clipboard-copy__group">
{ self.expander(ctx) }
<TextInput
r#ref={self.text_ref.clone()}
readonly={ctx.props().readonly | self.expanded}
value={value}
name={ctx.props().name.clone()}
id={ctx.props().id.clone()}
oninput={ctx.link().callback(|_|Msg::Sync)}
/>
<Tooltip text={self.message}>
<Button aria_label="Copy to clipboard" variant={Variant::Control} icon={Icon::Copy} onclick={ctx.link().callback(|_|Msg::Copy)}/>
</Tooltip>
</div>
{ self.expanded(ctx) }
</>
}
}
}}
</div>
}
}
}
impl Clipboard {
fn value(&self, ctx: &Context<Self>) -> String {
self.value
.clone()
.unwrap_or_else(|| ctx.props().value.clone())
}
fn trigger_message(&mut self, ctx: &Context<Self>, msg: &'static str) {
self.message = msg;
self.task = Some({
let link = ctx.link().clone();
Timeout::new(2_000, move || {
link.send_message(Msg::Reset);
})
});
}
fn do_copy(&self, ctx: &Context<Self>) {
let s = self.value(&ctx);
let ok: Callback<()> = ctx.link().callback(|_| Msg::Copied);
let err: Callback<&'static str> = ctx.link().callback(|s| Msg::Failed(s));
wasm_bindgen_futures::spawn_local(async move {
match copy_to_clipboard(s).await {
Ok(_) => ok.emit(()),
Err(_) => err.emit(FAILED_MESSAGE),
};
});
}
fn expander(&self, ctx: &Context<Self>) -> Html {
if !ctx.props().variant.is_expandable() {
return Default::default();
}
let onclick = ctx.link().callback(|_| Msg::ToggleExpand);
return html! {
<Button
expanded={self.expanded}
variant={Variant::Control}
onclick={onclick}>
<div class="pf-c-clipboard-copy__toggle-icon">
{ Icon::AngleRight }
</div>
</Button>
};
}
fn expanded(&self, ctx: &Context<Self>) -> Html {
if !self.expanded {
return Default::default();
}
let value = self.value(ctx);
html! {
<div
ref={self.details_ref.clone()}
class="pf-c-clipboard-copy__expandable-content"
contenteditable={(!ctx.props().readonly).to_string()}
oninput={ctx.link().callback(|_|Msg::Sync)}
>
if ctx.props().code {
<pre>{ value }</pre>
} else {
{ value }
}
</div>
}
}
/// Sync the value between internal, text field or details.
fn sync_from_edit(&mut self, ctx: &Context<Self>) {
if ctx.props().readonly || ctx.props().variant.is_inline() {
return;
}
let value = if self.expanded {
// from div to input
let ele: Option<Element> = self.details_ref.cast::<Element>();
ele.and_then(|ele| ele.text_content())
.unwrap_or_else(|| "".into())
} else {
// from input to div
let ele: Option<HtmlInputElement> = self.text_ref.cast::<HtmlInputElement>();
ele.map(|ele| ele.value()).unwrap_or_else(|| "".into())
};
log::info!("New value: {}", value);
// sync back
if self.expanded {
if let Some(ele) = self.text_ref.cast::<HtmlInputElement>() {
ele.set_value(&value);
}
} else {
if let Some(ele) = self.details_ref.cast::<Element>() {
ele.set_text_content(Some(&value));
}
}
// sync to internal state
self.value = Some(value);
}Trait Implementations§
source§impl Clone for ClipboardVariant
impl Clone for ClipboardVariant
source§fn clone(&self) -> ClipboardVariant
fn clone(&self) -> ClipboardVariant
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moresource§impl Debug for ClipboardVariant
impl Debug for ClipboardVariant
source§impl Default for ClipboardVariant
impl Default for ClipboardVariant
source§impl PartialEq<ClipboardVariant> for ClipboardVariant
impl PartialEq<ClipboardVariant> for ClipboardVariant
source§fn eq(&self, other: &ClipboardVariant) -> bool
fn eq(&self, other: &ClipboardVariant) -> bool
impl Eq for ClipboardVariant
impl StructuralEq for ClipboardVariant
impl StructuralPartialEq for ClipboardVariant
Auto Trait Implementations§
impl RefUnwindSafe for ClipboardVariant
impl Send for ClipboardVariant
impl Sync for ClipboardVariant
impl Unpin for ClipboardVariant
impl UnwindSafe for ClipboardVariant
Blanket Implementations§
source§impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
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>
source§impl<T> IntoPropValue<Option<T>> for T
impl<T> IntoPropValue<Option<T>> for T
source§fn into_prop_value(self) -> Option<T>
fn into_prop_value(self) -> Option<T>
Convert
self to a value of a Properties struct.source§impl<T> IntoPropValue<T> for T
impl<T> IntoPropValue<T> for T
source§fn into_prop_value(self) -> T
fn into_prop_value(self) -> T
Convert
self to a value of a Properties struct.