Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add example for truncate #36

Merged
merged 2 commits into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions .github/workflows/pr-preview-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@ jobs:
github.event.workflow_run.conclusion == 'success'
steps:
- name: Download dist
uses: actions/github-script@v3
uses: actions/github-script@v6
with:
script: |
var artifacts = await github.actions.listWorkflowRunArtifacts({
var artifacts = await github.rest.actions.listWorkflowRunArtifacts({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: ${{github.event.workflow_run.id }},
});
var matchArtifact = artifacts.data.artifacts.filter((artifact) => {
return artifact.name == "dist"
})[0];
var download = await github.actions.downloadArtifact({
var download = await github.rest.actions.downloadArtifact({
owner: context.repo.owner,
repo: context.repo.repo,
artifact_id: matchArtifact.id,
Expand All @@ -33,18 +33,18 @@ jobs:
var fs = require('fs');
fs.writeFileSync('${{github.workspace}}/dist.zip', Buffer.from(download.data));
- name: Download PR number
uses: actions/github-script@v3
uses: actions/github-script@v6
with:
script: |
var artifacts = await github.actions.listWorkflowRunArtifacts({
var artifacts = await github.rest.actions.listWorkflowRunArtifacts({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: ${{github.event.workflow_run.id }},
});
var matchArtifact = artifacts.data.artifacts.filter((artifact) => {
return artifact.name == "pr"
})[0];
var download = await github.actions.downloadArtifact({
var download = await github.rest.actions.downloadArtifact({
owner: context.repo.owner,
repo: context.repo.repo,
artifact_id: matchArtifact.id,
Expand All @@ -57,7 +57,7 @@ jobs:
- run: unzip pr.zip

- name: Generate issue_number
uses: actions/github-script@v3
uses: actions/github-script@v6
id: issue_number
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
Expand All @@ -67,13 +67,13 @@ jobs:
result-encoding: string

- name: Generate Surge URL
uses: actions/github-script@v3
uses: actions/github-script@v6
id: surge-url
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const issue_number = ${{steps.issue_number.outputs.result}};
return `patternfly-yew-quickstarts-pr-${issue_number}-preview.surge.sh`;
return `patternfly-yew-quickstart-pr-${issue_number}-preview.surge.sh`;
result-encoding: string
- name: Install Surge
run: npm install -g surge
Expand All @@ -83,6 +83,6 @@ jobs:
- name: Post URL as PR comment
uses: mshick/add-pr-comment@v2
with:
message: "🚀 Deployed Preview: http://${{steps.surge-url.outputs.result}} ✨"
message: "🚀 Deployed Preview: https://${{steps.surge-url.outputs.result}} ✨"
repo-token: ${{ secrets.BOT_TOKEN }}
issue: ${{steps.issue_number.outputs.result}}
7 changes: 3 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "patternfly-yew-quickstart"
version = "0.5.0"
version = "0.5.1"
authors = ["Jens Reimann <jreimann@redhat.com>"]
edition = "2021"
license = "Apache-2.0"
Expand All @@ -13,7 +13,7 @@ browser-panic-hook = "0.2"
chrono = { version = "0.4.30", default-features = false, features = ["wasmbind"] }
gloo-utils = "0.2"
log = "0.4"
patternfly-yew = { version = "0.5.0", features = ["tree", "dual_list_selector", "icons-fab"] }
patternfly-yew = { version = "0.5.1", features = ["tree", "dual_list_selector", "icons-fab"] }
popper-rs = { version = "0.3.0", features = ["yew", "debug"] }
serde_json = "1"
strum = { version = "0.25", features = ["derive"] }
Expand All @@ -35,7 +35,7 @@ features = [

[patch.crates-io]
#patternfly-yew = { path = "../patternfly-yew" }
#patternfly-yew = { git = "https://github.com/ctron/patternfly-yew", rev = "4b5025843efe1c9fce5c85168f5f5971005a0886" } # FIXME: awaiting release
patternfly-yew = { git = "https://github.com/ctron/patternfly-yew", rev = "ef507153eabf2dd3ab4dff2ece3325896510daba" } # FIXME: awaiting release
#yew-nested-router = { path = "../yew-nested-router" }
#yew-more-hooks = { git = "https://github.com/ctron/yew-more-hooks", rev = "f535bb2e7b227aac7010035215c11d4aeae6cb62" } # FIXME: awaiting release
#yew-more-hooks = { path = "../yew-more-hooks" }
Expand Down
7 changes: 5 additions & 2 deletions src/app/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ pub enum Component {
Toast,
Tooltip,
Tree,
Truncate,
}

#[derive(Debug, Clone, Default, PartialEq, Eq, Target)]
Expand Down Expand Up @@ -177,6 +178,7 @@ fn switch_app_route(target: AppRoute) -> Html {
Component::Toast => html! {<components::ToastExample/>},
Component::Tooltip => html! {<components::TooltipExample/>},
Component::Tree => html! {<components::TreeExample/>},
Component::Truncate => html! {<components::TruncateExample/>},
};

let layout = |target: Layout| match target {
Expand Down Expand Up @@ -314,6 +316,7 @@ fn page(props: &PageProps) -> Html {
<NavRouterItem<AppRoute> to={AppRoute::Component(Component::Toast)}>{"Toast"}</NavRouterItem<AppRoute>>
<NavRouterItem<AppRoute> to={AppRoute::Component(Component::Tooltip)}>{"Tooltip"}</NavRouterItem<AppRoute>>
<NavRouterItem<AppRoute> to={AppRoute::Component(Component::Tree)}>{"Tree"}</NavRouterItem<AppRoute>>
<NavRouterItem<AppRoute> to={AppRoute::Component(Component::Truncate)}>{"Truncate"}</NavRouterItem<AppRoute>>
</NavExpandable>
<NavExpandable title="Layouts">
<NavRouterItem<AppRoute> to={AppRoute::Layout(Layout::Bullseye)}>{"Bullseye"}</NavRouterItem<AppRoute>>
Expand Down Expand Up @@ -344,13 +347,13 @@ fn page(props: &PageProps) -> Html {

let backdropper = use_backdrop();

let onabout = Callback::from(move |_| {
let onabout = use_callback((), move |_, ()| {
if let Some(backdropper) = &backdropper {
backdropper.open(html!(<about::About/>));
}
});

let onthemeswitch = Callback::from(|state| match state {
let onthemeswitch = use_callback((), |state, ()| match state {
true => gloo_utils::document_element().set_class_name("pf-v5-theme-dark"),
false => gloo_utils::document_element().set_class_name(""),
});
Expand Down
4 changes: 3 additions & 1 deletion src/components/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ mod date;
mod description_list;
mod divider;
mod drawer;
mod dual_list_selector;
mod dropdown;
mod dual_list_selector;
mod empty;
mod expandable_section;
mod file_upload;
Expand All @@ -41,6 +41,7 @@ mod title;
mod toast;
mod tooltip;
mod tree;
mod truncate;

pub use accordion::*;
pub use alert::*;
Expand Down Expand Up @@ -85,3 +86,4 @@ pub use title::*;
pub use toast::*;
pub use tooltip::*;
pub use tree::*;
pub use truncate::*;
32 changes: 32 additions & 0 deletions src/components/truncate/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
use crate::example;
use crate::example::ExamplePage;
use patternfly_yew::prelude::*;
use yew::prelude::*;

#[function_component(TruncateExample)]
pub fn truncate_example() -> Html {
let example1 = example! ("Default" => "truncate.1.example");
let example2 = example! ("Start" => "truncate.2.example");
let example3 = example! ("Middle" => "truncate.3.example");
let example4 = example! ("Middle (explicit)" => "truncate.4.example");

#[function_component(Resize)]
fn resize(props: &ChildrenProperties) -> Html {
html!(
<div style="resize: horizontal; border: var(--pf-v5-global--BorderWidth--sm) solid var(--pf-v5-global--BorderColor--100); padding: var(--pf-v5-global--spacer--md); overflow: auto; width: 350px; max-width: 100%;">
{ props.children.clone() }
</div>
)
}

html! (
<>
<ExamplePage title="Truncate">
{example1}
{example2}
{example3}
{example4}
</ExamplePage>
</>
)
}
7 changes: 7 additions & 0 deletions src/components/truncate/truncate.1.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
html!(
<Resize>
<Truncate content="Vestibulum interdum risus et enim faucibus, sit amet molestie est accumsan." />
</Resize>
)
}
7 changes: 7 additions & 0 deletions src/components/truncate/truncate.2.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
html!(
<Resize>
<Truncate content={"Vestibulum interdum risus et enim faucibus, sit amet molestie est accumsan.".truncate_start()} />
</Resize>
)
}
7 changes: 7 additions & 0 deletions src/components/truncate/truncate.3.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
html!(
<Resize>
<Truncate content={"Vestibulum interdum risus et enim faucibus, sit amet molestie est accumsan.".truncate_before(10)} />
</Resize>
)
}
10 changes: 10 additions & 0 deletions src/components/truncate/truncate.4.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
html!(
<Resize>
<Truncate content={TruncateContent::Middle(
"Vestibulum interdum risus et enim faucibus, sit amet molestie est".into(),
" accumsan.".into()
)} />
</Resize>
)
}