use gpui::{ App, AppContext, Context, Entity, Focusable, IntoElement, ParentElement, Render, SharedString, Styled, Window, }; use gpui_component::{ clipboard::Clipboard, input::{InputState, TextInput}, label::Label, v_flex, ContextModal, }; use crate::section; pub struct ClipboardStory { focus_handle: gpui::FocusHandle, url_state: Entity, masked: bool, } impl super::Story for ClipboardStory { fn title() -> &'static str { "Clipboard" } fn description() -> &'static str { "A button that helps you copy text or other content to your clipboard." } fn new_view(window: &mut Window, cx: &mut App) -> Entity { Self::view(window, cx) } } impl ClipboardStory { pub(crate) fn new(window: &mut Window, cx: &mut App) -> Self { let url_state = cx.new(|cx| InputState::new(window, cx).default_value("https://github.com")); Self { url_state, focus_handle: cx.focus_handle(), masked: false, } } pub fn view(window: &mut Window, cx: &mut App) -> Entity { cx.new(|cx| Self::new(window, cx)) } } impl Focusable for ClipboardStory { fn focus_handle(&self, _: &gpui::App) -> gpui::FocusHandle { self.focus_handle.clone() } } impl Render for ClipboardStory { fn render(&mut self, _: &mut Window, cx: &mut Context) -> impl IntoElement { v_flex() .gap_6() .child( section("Clipboard").max_w_md().child( Clipboard::new("clipboard1") .content(|_, _| Label::new("A clipboard button")) .value_fn({ let view = cx.entity().clone(); move |_, cx| { SharedString::from(format!("masked :{}", view.read(cx).masked)) } }) .on_copied(|value, window, cx| { window.push_notification(format!("Copied value: {}", value), cx) }), ), ) .child( section("With in an Input").max_w_md().child( TextInput::new(&self.url_state).suffix( Clipboard::new("clipboard2") .value_fn({ let state = self.url_state.clone(); move |_, cx| state.read(cx).value() }) .on_copied(|value, window, cx| { window.push_notification(format!("Copied value: {}", value), cx) }), ), ), ) } }