yew_consent/
lib.rs

1//! Managing consent with Yew
2//!
3//! # Usage
4//!
5//! The idea is to ask the user for some kind of consent, which is modeled by
6//! [`ConsentState`] plus the additional type `T` (which can also be `()`) if no further
7//! specializations are needed.
8//!
9//! Wrap the main content of your application with the [`component::Consent`] component. It will
10//! load the consent state from the browser storage, and then either show the `ask` content, which
11//! is responsible to get the consent state. Or it will show the "children", wrapping them with the
12//! consent state as defined by the user.
13//!
14//! All component below the [`component::Consent`] component can use the [`hook::use_consent`] hook,
15//! to fetch the [`ConsentState`]. They can also use the [`hook::use_consent_context`] to change
16//! the consent state later on.
17//!
18//! # Examples
19//!
20//! See the example project in the `example` folder.
21use std::fmt::Debug;
22
23pub mod component;
24pub mod hook;
25pub mod prelude;
26
27/// The state of the consent.
28///
29/// There are two basic states: [`ConsentState::No`], which means that the user rejects everything.
30/// And [`ConsentState::Yes`], which means that the user agrees, but there may be additional
31/// customizations, based on the type of `T` being used.
32#[derive(Clone, Debug, Default, PartialEq, Eq, serde::Deserialize, serde::Serialize)]
33#[serde(rename_all = "lowercase")]
34pub enum ConsentState<T> {
35    /// The user consents. May have additional payload, use `()` if none.
36    Yes(T),
37    /// The user does not consent.
38    #[default]
39    No,
40}