Initial commit
This commit is contained in:
24
.github/workflows/audit.yml
vendored
Normal file
24
.github/workflows/audit.yml
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
name: Security audit
|
||||
|
||||
on:
|
||||
push:
|
||||
paths:
|
||||
- '**/Cargo.toml'
|
||||
- '**/Cargo.lock'
|
||||
|
||||
jobs:
|
||||
security_audit:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v3
|
||||
- name: Install Rust
|
||||
uses: actions-rs/toolchain@v1
|
||||
with:
|
||||
toolchain: stable
|
||||
profile: minimal
|
||||
override: true
|
||||
- uses: Swatinem/rust-cache@v1
|
||||
- uses: actions-rs/audit-check@v1
|
||||
with:
|
||||
token: ${{ secrets.GITHUB_TOKEN }}
|
||||
112
.github/workflows/ci.yml
vendored
Normal file
112
.github/workflows/ci.yml
vendored
Normal file
@@ -0,0 +1,112 @@
|
||||
name: CI
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
pull_request:
|
||||
|
||||
jobs:
|
||||
|
||||
rustfmt:
|
||||
name: Rustfmt
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v3
|
||||
- name: Install Rust toolchain
|
||||
uses: actions-rs/toolchain@v1
|
||||
with:
|
||||
toolchain: stable
|
||||
profile: minimal
|
||||
components: rustfmt
|
||||
- name: Check formatting
|
||||
uses: actions-rs/cargo@v1
|
||||
with:
|
||||
command: fmt
|
||||
args: --all -- --check
|
||||
|
||||
build:
|
||||
name: Build
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v3
|
||||
- name: Install Rust toolchain
|
||||
uses: actions-rs/toolchain@v1
|
||||
with:
|
||||
toolchain: stable
|
||||
profile: minimal
|
||||
- uses: Swatinem/rust-cache@v1
|
||||
with:
|
||||
sharedKey: ci
|
||||
- uses: actions-rs/cargo@v1
|
||||
with:
|
||||
command: check
|
||||
args: --all-features --workspace
|
||||
|
||||
test:
|
||||
needs: build
|
||||
name: Test Suite
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v3
|
||||
- name: Install Rust toolchain
|
||||
uses: actions-rs/toolchain@v1
|
||||
with:
|
||||
toolchain: stable
|
||||
profile: minimal
|
||||
- uses: Swatinem/rust-cache@v1
|
||||
with:
|
||||
sharedKey: ci
|
||||
- uses: actions-rs/cargo@v1
|
||||
with:
|
||||
command: test
|
||||
args: --all-features --workspace
|
||||
|
||||
clippy:
|
||||
needs: build
|
||||
name: Clippy
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v3
|
||||
- name: Install Rust toolchain
|
||||
uses: actions-rs/toolchain@v1
|
||||
with:
|
||||
toolchain: stable
|
||||
profile: minimal
|
||||
components: clippy
|
||||
- uses: Swatinem/rust-cache@v1
|
||||
with:
|
||||
sharedKey: ci
|
||||
- name: Clippy check
|
||||
uses: actions-rs/cargo@v1
|
||||
with:
|
||||
command: clippy
|
||||
args: --all-targets --all-features --workspace -- -D warnings
|
||||
|
||||
coverage:
|
||||
name: Code coverage
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v3
|
||||
- name: Install Rust toolchain
|
||||
uses: actions-rs/toolchain@v1
|
||||
with:
|
||||
toolchain: stable
|
||||
profile: minimal
|
||||
- uses: Swatinem/rust-cache@v1
|
||||
- name: Run cargo-tarpaulin
|
||||
uses: actions-rs/tarpaulin@v0.1
|
||||
with:
|
||||
args: '--all-features --workspace --ignore-tests --out Lcov'
|
||||
- name: Upload to Coveralls
|
||||
# upload only if push
|
||||
if: ${{ github.event_name == 'push' }}
|
||||
uses: coverallsapp/github-action@master
|
||||
with:
|
||||
github-token: ${{ secrets.GITHUB_TOKEN }}
|
||||
path-to-lcov: './lcov.info'
|
||||
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
/target
|
||||
Cargo.lock
|
||||
18
.pre-commit-config.yaml
Normal file
18
.pre-commit-config.yaml
Normal file
@@ -0,0 +1,18 @@
|
||||
repos:
|
||||
- repo: local
|
||||
hooks:
|
||||
- id: format
|
||||
name: format
|
||||
language: system
|
||||
pass_filenames: false
|
||||
entry: cargo fmt --all -- --check
|
||||
- id: check
|
||||
name: check
|
||||
language: system
|
||||
pass_filenames: false
|
||||
entry: cargo check --tests
|
||||
- id: clippy
|
||||
name: clippy
|
||||
language: system
|
||||
pass_filenames: false
|
||||
entry: cargo clippy -- -D warnings
|
||||
9
Cargo.toml
Normal file
9
Cargo.toml
Normal file
@@ -0,0 +1,9 @@
|
||||
[package]
|
||||
name = "uikit-rs"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
authors = ["David Rousselie <david@rousselie.name>"]
|
||||
|
||||
[dependencies]
|
||||
yew = "0.19"
|
||||
regex = "1.5.5"
|
||||
73
LICENSE
Normal file
73
LICENSE
Normal file
@@ -0,0 +1,73 @@
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives.
|
||||
|
||||
Copyright 2022 David Rousselie
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
7
README.md
Normal file
7
README.md
Normal file
@@ -0,0 +1,7 @@
|
||||
# UIkit-rs
|
||||
|
||||
[](http://www.apache.org/licenses/)
|
||||
[](https://coveralls.io/github/dax/uikit-rs?branch=main)
|
||||
[](https://github.com/dax/uikit-rs/actions)
|
||||
|
||||
This is a [UIkit](https://getuikit.com/) binding for [Yew](https://yew.rs/).
|
||||
109
src/card.rs
Normal file
109
src/card.rs
Normal file
@@ -0,0 +1,109 @@
|
||||
use yew::{classes, function_component, html, Children, Classes, Properties};
|
||||
|
||||
use super::{Margin, Padding, Text, Width};
|
||||
|
||||
#[allow(dead_code)]
|
||||
#[derive(Debug, PartialEq, Eq, Copy, Clone)]
|
||||
pub enum CardSize {
|
||||
Small,
|
||||
}
|
||||
|
||||
impl From<CardSize> for Classes {
|
||||
fn from(card_size: CardSize) -> Self {
|
||||
format!("uk-card-{:?}", card_size).to_lowercase().into()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Eq, Copy, Clone)]
|
||||
pub enum CardStyle {
|
||||
Default,
|
||||
Primary,
|
||||
Secondary,
|
||||
}
|
||||
|
||||
impl From<CardStyle> for Classes {
|
||||
fn from(card_style: CardStyle) -> Self {
|
||||
format!("uk-card-{:?}", card_style).to_lowercase().into()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Properties, PartialEq)]
|
||||
pub struct CardProps {
|
||||
#[prop_or_default]
|
||||
pub children: Children, // TODO: enum typed
|
||||
#[prop_or_default]
|
||||
pub size: Option<CardSize>,
|
||||
#[prop_or_default]
|
||||
pub style: Option<CardStyle>,
|
||||
#[prop_or_default]
|
||||
pub hover: bool,
|
||||
#[prop_or_default]
|
||||
pub width: Option<Width>,
|
||||
#[prop_or_default]
|
||||
pub class: Classes,
|
||||
}
|
||||
|
||||
#[function_component(Card)]
|
||||
pub fn card(
|
||||
CardProps {
|
||||
children,
|
||||
size,
|
||||
style,
|
||||
hover,
|
||||
width,
|
||||
class,
|
||||
}: &CardProps,
|
||||
) -> Html {
|
||||
html! {
|
||||
<div class={classes!("uk-card", style, size, hover.then(|| "uk-card-hover"), width, class.clone())}>
|
||||
{ for children.iter() }
|
||||
</div>
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Properties, PartialEq)]
|
||||
pub struct CardBodyProps {
|
||||
#[prop_or_default]
|
||||
pub children: Children,
|
||||
#[prop_or_default]
|
||||
pub padding: Vec<Padding>,
|
||||
#[prop_or_default]
|
||||
pub margin: Vec<Margin>,
|
||||
}
|
||||
|
||||
#[function_component(CardBody)]
|
||||
pub fn card_body(
|
||||
CardBodyProps {
|
||||
children,
|
||||
padding,
|
||||
margin,
|
||||
}: &CardBodyProps,
|
||||
) -> Html {
|
||||
html! {
|
||||
<div class={classes!("uk-card-body", padding.clone(), margin.clone())}>
|
||||
{ for children.iter() }
|
||||
</div>
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Properties, PartialEq)]
|
||||
pub struct CardTitleProps {
|
||||
#[prop_or_default]
|
||||
pub children: Children,
|
||||
#[prop_or_default]
|
||||
pub text_style: Vec<Text>,
|
||||
}
|
||||
|
||||
#[function_component(CardTitle)]
|
||||
pub fn card_title(
|
||||
CardTitleProps {
|
||||
children,
|
||||
text_style,
|
||||
}: &CardTitleProps,
|
||||
) -> Html {
|
||||
html! {
|
||||
<h3 class={classes!("uk-card-title", text_style.clone())}>
|
||||
{ for children.iter() }
|
||||
</h3>
|
||||
}
|
||||
}
|
||||
34
src/container.rs
Normal file
34
src/container.rs
Normal file
@@ -0,0 +1,34 @@
|
||||
use yew::{classes, function_component, html, Children, Classes, Properties};
|
||||
|
||||
#[allow(dead_code)]
|
||||
#[derive(Debug, PartialEq, Eq, Copy, Clone)]
|
||||
pub enum ContainerSize {
|
||||
XSmall,
|
||||
Small,
|
||||
Large,
|
||||
XLarge,
|
||||
Expand,
|
||||
}
|
||||
|
||||
impl From<ContainerSize> for Classes {
|
||||
fn from(size: ContainerSize) -> Self {
|
||||
format!("uk-container-{:?}", size).to_lowercase().into()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Properties, PartialEq)]
|
||||
pub struct ContainerProps {
|
||||
#[prop_or_default]
|
||||
pub children: Children,
|
||||
#[prop_or_default]
|
||||
pub size: Option<ContainerSize>,
|
||||
}
|
||||
|
||||
#[function_component(Container)]
|
||||
pub fn container(ContainerProps { children, size }: &ContainerProps) -> Html {
|
||||
html! {
|
||||
<div class={classes!("uk-container", size)}>
|
||||
{ for children.iter() }
|
||||
</div>
|
||||
}
|
||||
}
|
||||
15
src/divider.rs
Normal file
15
src/divider.rs
Normal file
@@ -0,0 +1,15 @@
|
||||
use super::margin::Margin;
|
||||
use yew::{classes, function_component, html, Properties};
|
||||
|
||||
#[derive(Properties, PartialEq)]
|
||||
pub struct DividerProps {
|
||||
#[prop_or_default]
|
||||
pub margin: Vec<Margin>,
|
||||
}
|
||||
|
||||
#[function_component(Divider)]
|
||||
pub fn divider(DividerProps { margin }: &DividerProps) -> Html {
|
||||
html! {
|
||||
<hr class={classes!(margin.clone())} />
|
||||
}
|
||||
}
|
||||
54
src/filter.rs
Normal file
54
src/filter.rs
Normal file
@@ -0,0 +1,54 @@
|
||||
use super::width::Width;
|
||||
use super::UIKitComponent;
|
||||
use yew::{classes, function_component, html, Children, Classes, Html, Properties};
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub struct FilterData {
|
||||
pub class: String,
|
||||
pub label: String,
|
||||
}
|
||||
|
||||
#[derive(Properties, PartialEq)]
|
||||
pub struct FilterProps {
|
||||
#[prop_or_default]
|
||||
pub children: Children,
|
||||
#[prop_or_default]
|
||||
pub target: String,
|
||||
#[prop_or_default]
|
||||
pub filter_width: Option<Width>,
|
||||
#[prop_or_default]
|
||||
pub filter_component: Option<UIKitComponent>,
|
||||
#[prop_or_default]
|
||||
pub filter_class: Classes,
|
||||
#[prop_or_default]
|
||||
pub filters: Vec<FilterData>,
|
||||
}
|
||||
|
||||
#[function_component(Filter)]
|
||||
pub fn filter(
|
||||
FilterProps {
|
||||
children,
|
||||
target,
|
||||
filter_width,
|
||||
filter_component,
|
||||
filter_class,
|
||||
filters,
|
||||
}: &FilterProps,
|
||||
) -> Html {
|
||||
let filter = format!("target: {}", target);
|
||||
|
||||
html! {
|
||||
<div uk-filter={filter}>
|
||||
<ul class={classes!(filter_component, filter_class.clone(), filter_width)}>
|
||||
{
|
||||
filters.iter().map(|FilterData { class, label }|
|
||||
html! {
|
||||
<li uk-filter-control={class.clone()}><a href="#">{label}</a></li>
|
||||
}
|
||||
).collect::<Html>()
|
||||
}
|
||||
</ul>
|
||||
{ for children.iter() }
|
||||
</div>
|
||||
}
|
||||
}
|
||||
47
src/flex.rs
Normal file
47
src/flex.rs
Normal file
@@ -0,0 +1,47 @@
|
||||
use super::Width;
|
||||
use yew::{classes, function_component, html, Callback, Children, Classes, MouseEvent, Properties};
|
||||
|
||||
#[allow(dead_code)]
|
||||
#[derive(Debug, PartialEq, Eq, Copy, Clone)]
|
||||
pub enum FlexVerticalAlignement {
|
||||
Stretch,
|
||||
Top,
|
||||
Middle,
|
||||
Bottom,
|
||||
}
|
||||
|
||||
impl From<FlexVerticalAlignement> for Classes {
|
||||
fn from(vertical_alignement: FlexVerticalAlignement) -> Self {
|
||||
format!("uk-flex-{:?}", vertical_alignement)
|
||||
.to_lowercase()
|
||||
.into()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Properties, PartialEq)]
|
||||
pub struct FlexProps {
|
||||
#[prop_or_default]
|
||||
pub children: Children,
|
||||
#[prop_or_default]
|
||||
pub vertical_alignement: Option<FlexVerticalAlignement>,
|
||||
#[prop_or_default]
|
||||
pub width: Option<Width>,
|
||||
#[prop_or_default]
|
||||
pub onclick: Callback<MouseEvent>,
|
||||
}
|
||||
|
||||
#[function_component(Flex)]
|
||||
pub fn container(
|
||||
FlexProps {
|
||||
children,
|
||||
vertical_alignement,
|
||||
width,
|
||||
onclick,
|
||||
}: &FlexProps,
|
||||
) -> Html {
|
||||
html! {
|
||||
<div class={classes!("uk-flex", vertical_alignement, width)} onclick={onclick}>
|
||||
{ for children.iter() }
|
||||
</div>
|
||||
}
|
||||
}
|
||||
65
src/grid.rs
Normal file
65
src/grid.rs
Normal file
@@ -0,0 +1,65 @@
|
||||
use super::{ChildWidth, FlexVerticalAlignement, Margin, Text};
|
||||
use yew::{classes, function_component, html, Children, Classes, Properties};
|
||||
|
||||
#[allow(dead_code)]
|
||||
#[derive(Debug, PartialEq, Eq, Copy, Clone)]
|
||||
pub enum GridGapSize {
|
||||
Small,
|
||||
Medium,
|
||||
Large,
|
||||
Collapse,
|
||||
}
|
||||
|
||||
impl From<GridGapSize> for Classes {
|
||||
fn from(gap_size: GridGapSize) -> Self {
|
||||
format!("uk-grid-{:?}", gap_size).to_lowercase().into()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Properties, PartialEq)]
|
||||
pub struct GridProps {
|
||||
#[prop_or_default]
|
||||
pub children: Children,
|
||||
#[prop_or_default]
|
||||
pub gap_size: Option<GridGapSize>,
|
||||
#[prop_or_default]
|
||||
pub margin: Vec<Margin>,
|
||||
#[prop_or_default]
|
||||
pub height_match: bool,
|
||||
#[prop_or_default]
|
||||
pub vertical_alignement: Option<FlexVerticalAlignement>,
|
||||
#[prop_or_default]
|
||||
pub child_width: Option<ChildWidth>,
|
||||
#[prop_or_default]
|
||||
pub text_style: Vec<Text>,
|
||||
#[prop_or_default]
|
||||
pub class: Classes,
|
||||
}
|
||||
|
||||
#[function_component(Grid)]
|
||||
pub fn grid(
|
||||
GridProps {
|
||||
children,
|
||||
gap_size,
|
||||
margin,
|
||||
height_match,
|
||||
vertical_alignement,
|
||||
child_width,
|
||||
text_style,
|
||||
class,
|
||||
}: &GridProps,
|
||||
) -> Html {
|
||||
html! {
|
||||
<div class={classes!(
|
||||
class.clone(),
|
||||
gap_size,
|
||||
margin.clone(),
|
||||
vertical_alignement,
|
||||
child_width,
|
||||
text_style.clone(),
|
||||
height_match.then(|| "uk-grid-match")
|
||||
)} uk-grid="">
|
||||
{ for children.iter() }
|
||||
</div>
|
||||
}
|
||||
}
|
||||
68
src/icon.rs
Normal file
68
src/icon.rs
Normal file
@@ -0,0 +1,68 @@
|
||||
use super::{Margin, Text};
|
||||
use regex::Regex;
|
||||
use std::fmt;
|
||||
use yew::{classes, function_component, html, Callback, MouseEvent, Properties};
|
||||
|
||||
#[allow(dead_code)]
|
||||
#[derive(Debug, PartialEq, Eq, Copy, Clone)]
|
||||
pub enum IconType {
|
||||
Check,
|
||||
FileEdit,
|
||||
Bookmark,
|
||||
TriangleLeft,
|
||||
TriangleRight,
|
||||
TriangleDown,
|
||||
TriangleUp,
|
||||
Plus,
|
||||
}
|
||||
|
||||
impl fmt::Display for IconType {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
let uppercase_re = Regex::new("(.)([A-Z])").unwrap();
|
||||
write!(
|
||||
f,
|
||||
"{}",
|
||||
uppercase_re
|
||||
.replace(&format!("{:?}", self), "$1-$2")
|
||||
.to_lowercase()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Properties, PartialEq)]
|
||||
pub struct IconProps {
|
||||
pub icon_type: IconType,
|
||||
#[prop_or_default]
|
||||
pub text_style: Vec<Text>,
|
||||
#[prop_or_default]
|
||||
pub margin: Vec<Margin>,
|
||||
#[prop_or_default]
|
||||
pub href: Option<String>,
|
||||
#[prop_or_default]
|
||||
pub onclick: Callback<MouseEvent>,
|
||||
}
|
||||
|
||||
#[function_component(Icon)]
|
||||
pub fn icon(
|
||||
IconProps {
|
||||
icon_type,
|
||||
text_style,
|
||||
margin,
|
||||
href,
|
||||
onclick,
|
||||
}: &IconProps,
|
||||
) -> Html {
|
||||
if let Some(href) = href {
|
||||
html! {
|
||||
<a href={href.clone()}
|
||||
onclick={onclick}
|
||||
class={classes!(text_style.clone(), margin.clone())}
|
||||
uk-icon={format!("icon: {}", icon_type)} />
|
||||
}
|
||||
} else {
|
||||
html! {
|
||||
<span class={classes!(text_style.clone(), margin.clone())}
|
||||
uk-icon={format!("icon: {}", icon_type)} />
|
||||
}
|
||||
}
|
||||
}
|
||||
16
src/iconnav.rs
Normal file
16
src/iconnav.rs
Normal file
@@ -0,0 +1,16 @@
|
||||
use yew::{classes, function_component, html, Children, Properties};
|
||||
|
||||
#[derive(Properties, PartialEq)]
|
||||
pub struct IconNavProps {
|
||||
#[prop_or_default]
|
||||
pub children: Children,
|
||||
}
|
||||
|
||||
#[function_component(IconNav)]
|
||||
pub fn icon_nav(IconNavProps { children }: &IconNavProps) -> Html {
|
||||
html! {
|
||||
<div class={classes!("uk-iconnav")}>
|
||||
{ for children.iter() }
|
||||
</div>
|
||||
}
|
||||
}
|
||||
43
src/lib.rs
Normal file
43
src/lib.rs
Normal file
@@ -0,0 +1,43 @@
|
||||
use yew::Classes;
|
||||
|
||||
pub mod card;
|
||||
pub mod container;
|
||||
pub mod divider;
|
||||
pub mod filter;
|
||||
pub mod flex;
|
||||
pub mod grid;
|
||||
pub mod icon;
|
||||
pub mod iconnav;
|
||||
pub mod link;
|
||||
pub mod margin;
|
||||
pub mod padding;
|
||||
pub mod section;
|
||||
pub mod text;
|
||||
pub mod width;
|
||||
|
||||
pub use card::*;
|
||||
pub use container::*;
|
||||
pub use divider::*;
|
||||
pub use filter::*;
|
||||
pub use flex::*;
|
||||
pub use grid::*;
|
||||
pub use icon::*;
|
||||
pub use iconnav::*;
|
||||
pub use link::*;
|
||||
pub use margin::*;
|
||||
pub use padding::*;
|
||||
pub use section::*;
|
||||
pub use text::*;
|
||||
pub use width::*;
|
||||
|
||||
#[allow(dead_code)]
|
||||
#[derive(Debug, PartialEq, Eq, Copy, Clone)]
|
||||
pub enum UIKitComponent {
|
||||
SubNav,
|
||||
}
|
||||
|
||||
impl From<UIKitComponent> for Classes {
|
||||
fn from(component: UIKitComponent) -> Self {
|
||||
format!("uk-{:?}", component).to_lowercase().into()
|
||||
}
|
||||
}
|
||||
26
src/link.rs
Normal file
26
src/link.rs
Normal file
@@ -0,0 +1,26 @@
|
||||
use yew::{function_component, html, Callback, Children, MouseEvent, Properties};
|
||||
|
||||
#[derive(Properties, PartialEq)]
|
||||
pub struct LinkProps {
|
||||
#[prop_or_default]
|
||||
pub children: Children,
|
||||
#[prop_or_default]
|
||||
pub href: String,
|
||||
#[prop_or_default]
|
||||
pub onclick: Callback<MouseEvent>,
|
||||
}
|
||||
|
||||
#[function_component(Link)]
|
||||
pub fn link(
|
||||
LinkProps {
|
||||
children,
|
||||
href,
|
||||
onclick,
|
||||
}: &LinkProps,
|
||||
) -> Html {
|
||||
html! {
|
||||
<a href={href.clone()} onclick={onclick}>
|
||||
{ for children.iter() }
|
||||
</a>
|
||||
}
|
||||
}
|
||||
64
src/margin.rs
Normal file
64
src/margin.rs
Normal file
@@ -0,0 +1,64 @@
|
||||
use regex::Regex;
|
||||
use yew::Classes;
|
||||
|
||||
#[allow(dead_code)]
|
||||
#[allow(non_camel_case_types)]
|
||||
#[derive(Debug, PartialEq, Eq, Copy, Clone)]
|
||||
pub enum Margin {
|
||||
Default,
|
||||
Top,
|
||||
Bottom,
|
||||
Left,
|
||||
Right,
|
||||
Small,
|
||||
SmallTop,
|
||||
SmallBottom,
|
||||
SmallLeft,
|
||||
SmallRight,
|
||||
Medium,
|
||||
MediumTop,
|
||||
MediumBottom,
|
||||
MediumLeft,
|
||||
MediumRight,
|
||||
Large,
|
||||
LargeTop,
|
||||
LargeBottom,
|
||||
LargeLeft,
|
||||
LargeRight,
|
||||
Xlarge,
|
||||
XlargeTop,
|
||||
XlargeBottom,
|
||||
XlargeLeft,
|
||||
XlargeRight,
|
||||
Remove,
|
||||
RemoveTop,
|
||||
RemoveBottom,
|
||||
RemoveLeft,
|
||||
RemoveRight,
|
||||
RemoveVertical,
|
||||
RemoveAdjacent,
|
||||
RemoveFirstChild,
|
||||
RemoveLastChild,
|
||||
RemoveLeft_s,
|
||||
RemoveRight_s,
|
||||
RemoveLeft_m,
|
||||
RemoveRight_m,
|
||||
RemoveLeft_l,
|
||||
RemoveRight_l,
|
||||
RemoveLeft_xl,
|
||||
RemoveRight_xl,
|
||||
}
|
||||
|
||||
impl From<Margin> for Classes {
|
||||
fn from(margin: Margin) -> Self {
|
||||
let uppercase_re = Regex::new("(.)([A-Z])").unwrap();
|
||||
let class = match margin {
|
||||
Margin::Default => "uk-margin".to_string(),
|
||||
_ => uppercase_re
|
||||
.replace(&format!("uk-margin{:?}", margin), "$1-$2")
|
||||
.replace('_', "@")
|
||||
.to_lowercase(),
|
||||
};
|
||||
class.into()
|
||||
}
|
||||
}
|
||||
30
src/padding.rs
Normal file
30
src/padding.rs
Normal file
@@ -0,0 +1,30 @@
|
||||
use regex::Regex;
|
||||
use yew::Classes;
|
||||
|
||||
#[allow(dead_code)]
|
||||
#[derive(Debug, PartialEq, Eq, Copy, Clone)]
|
||||
pub enum Padding {
|
||||
Default,
|
||||
Small,
|
||||
Large,
|
||||
Remove,
|
||||
RemoveTop,
|
||||
RemoveBottom,
|
||||
RemoveLeft,
|
||||
RemoveRight,
|
||||
RemoveVertical,
|
||||
RemoveHorizontal,
|
||||
}
|
||||
|
||||
impl From<Padding> for Classes {
|
||||
fn from(padding: Padding) -> Self {
|
||||
let uppercase_re = Regex::new("(.)([A-Z])").unwrap();
|
||||
let class = match padding {
|
||||
Padding::Default => "uk-padding".to_string(),
|
||||
_ => uppercase_re
|
||||
.replace(&format!("uk-padding{:?}", padding), "$1-$2")
|
||||
.to_lowercase(),
|
||||
};
|
||||
class.into()
|
||||
}
|
||||
}
|
||||
33
src/section.rs
Normal file
33
src/section.rs
Normal file
@@ -0,0 +1,33 @@
|
||||
use yew::{classes, function_component, html, Children, Classes, Properties};
|
||||
|
||||
#[allow(dead_code)]
|
||||
#[derive(Debug, PartialEq, Eq, Copy, Clone)]
|
||||
pub enum SectionStyle {
|
||||
Default,
|
||||
Muted,
|
||||
Primary,
|
||||
Secondary,
|
||||
}
|
||||
|
||||
impl From<SectionStyle> for Classes {
|
||||
fn from(style: SectionStyle) -> Self {
|
||||
format!("uk-section-{:?}", style).to_lowercase().into()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Properties, PartialEq)]
|
||||
pub struct SectionProps {
|
||||
#[prop_or_default]
|
||||
pub children: Children,
|
||||
#[prop_or_default]
|
||||
pub style: Option<SectionStyle>,
|
||||
}
|
||||
|
||||
#[function_component(Section)]
|
||||
pub fn section(SectionProps { children, style }: &SectionProps) -> Html {
|
||||
html! {
|
||||
<div class={classes!("uk-section", style)}>
|
||||
{ for children.iter() }
|
||||
</div>
|
||||
}
|
||||
}
|
||||
65
src/text.rs
Normal file
65
src/text.rs
Normal file
@@ -0,0 +1,65 @@
|
||||
use regex::Regex;
|
||||
use yew::Classes;
|
||||
|
||||
#[allow(dead_code)]
|
||||
#[allow(non_camel_case_types)]
|
||||
#[derive(Debug, PartialEq, Eq, Copy, Clone)]
|
||||
pub enum Text {
|
||||
Lead,
|
||||
Meta,
|
||||
Small,
|
||||
Default,
|
||||
Large,
|
||||
Light,
|
||||
Normal,
|
||||
Bold,
|
||||
Lighter,
|
||||
Bolder,
|
||||
Italic,
|
||||
Capitalize,
|
||||
Uppercase,
|
||||
LowerCase,
|
||||
DecorationNone,
|
||||
Muted,
|
||||
Emphasis,
|
||||
Primary,
|
||||
Secondary,
|
||||
Success,
|
||||
Warning,
|
||||
Danger,
|
||||
Background,
|
||||
Left,
|
||||
Right,
|
||||
Center,
|
||||
Justify,
|
||||
Top,
|
||||
Middle,
|
||||
Bottom,
|
||||
Baseline,
|
||||
Truncate,
|
||||
Break,
|
||||
Nowrap,
|
||||
Left_s,
|
||||
Center_s,
|
||||
Right_s,
|
||||
Left_m,
|
||||
Center_m,
|
||||
Right_m,
|
||||
Left_l,
|
||||
Center_l,
|
||||
Right_l,
|
||||
Left_xl,
|
||||
Center_xl,
|
||||
Right_xl,
|
||||
}
|
||||
|
||||
impl From<Text> for Classes {
|
||||
fn from(text: Text) -> Self {
|
||||
let uppercase_re = Regex::new("(.)([A-Z])").unwrap();
|
||||
uppercase_re
|
||||
.replace(&format!("uk-text{:?}", text), "$1-$2")
|
||||
.replace('_', "@")
|
||||
.to_lowercase()
|
||||
.into()
|
||||
}
|
||||
}
|
||||
54
src/width.rs
Normal file
54
src/width.rs
Normal file
@@ -0,0 +1,54 @@
|
||||
use yew::Classes;
|
||||
|
||||
#[allow(dead_code)]
|
||||
#[derive(Debug, PartialEq, Eq, Copy, Clone)]
|
||||
pub enum Width {
|
||||
_1_1,
|
||||
_1_2,
|
||||
_1_3,
|
||||
_1_4,
|
||||
_1_5,
|
||||
_1_6,
|
||||
_2_3,
|
||||
_3_4,
|
||||
_4_5,
|
||||
_5_6,
|
||||
_Auto,
|
||||
_Expand,
|
||||
_Small,
|
||||
_Medium,
|
||||
_Large,
|
||||
_XLarge,
|
||||
_2XLarge,
|
||||
}
|
||||
|
||||
impl From<Width> for Classes {
|
||||
fn from(width: Width) -> Self {
|
||||
format!("uk-width{:?}", width)
|
||||
.replace('_', "-")
|
||||
.to_lowercase()
|
||||
.into()
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
#[derive(Debug, PartialEq, Eq, Copy, Clone)]
|
||||
pub enum ChildWidth {
|
||||
_1_1,
|
||||
_1_2,
|
||||
_1_3,
|
||||
_1_4,
|
||||
_1_5,
|
||||
_1_6,
|
||||
_Auto,
|
||||
_Expand,
|
||||
}
|
||||
|
||||
impl From<ChildWidth> for Classes {
|
||||
fn from(width: ChildWidth) -> Self {
|
||||
format!("uk-child-width{:?}", width)
|
||||
.replace('_', "-")
|
||||
.to_lowercase()
|
||||
.into()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user