diff --git a/redraw/CHANGELOG.md b/redraw/CHANGELOG.md index 4d6f0a9..41047a0 100644 --- a/redraw/CHANGELOG.md +++ b/redraw/CHANGELOG.md @@ -1,6 +1,8 @@ -## Unreleased +## v1.1.1 - 2024-12-23 +- Add documentation for every functions. - Bump minimal required versions. +- Add `offset_x`, `offset_y`, `altitude_angle` & `azimuth_angle`. ## v1.1.0 - 2024-21-08 diff --git a/redraw/gleam.toml b/redraw/gleam.toml index 42ad537..33a2295 100644 --- a/redraw/gleam.toml +++ b/redraw/gleam.toml @@ -1,6 +1,6 @@ name = "redraw" target = "javascript" -version = "1.1.0" +version = "1.1.1" # Fill out these fields if you intend to generate HTML documentation or publish # your project to the Hex package manager. diff --git a/redraw/src/events.ffi.mjs b/redraw/src/events.ffi.mjs index 1b36214..6ad84b9 100644 --- a/redraw/src/events.ffi.mjs +++ b/redraw/src/events.ffi.mjs @@ -102,6 +102,14 @@ export function clientY(event) { return event.clientY } +export function offsetX(event) { + return event.offsetX +} + +export function offsetY(event) { + return event.offsetY +} + export function metaKey(event) { return event.metaKey } @@ -170,6 +178,14 @@ export function isPrimary(event) { return event.isPrimary } +export function altitudeAngle(event) { + return event.altitudeAngle +} + +export function azimuthAngle(event) { + return event.azimuthAngle +} + export function pointerId(event) { return event.pointerId } diff --git a/redraw/src/redraw.gleam b/redraw/src/redraw.gleam index c25522f..63ea6d7 100644 --- a/redraw/src/redraw.gleam +++ b/redraw/src/redraw.gleam @@ -7,7 +7,7 @@ import redraw/internals/coerce.{coerce} // Component creation -/// Default Node in redraw. Use `component`-family functions to create components. +/// Default Node in Redraw. Use `component`-family functions to create components. /// Forwarded ref can be constructed using `forward_ref`-family functions, while /// external components can be used with `to_component`-family functions. pub type Component @@ -25,7 +25,10 @@ pub fn component( /// Create a Redraw component, with a `name`, and a `render` function. This /// component does not accept children. -pub fn component_(name name: String, render render: fn(props) -> Component) { +pub fn component_( + name name: String, + render render: fn(props) -> Component, +) -> fn(props) -> Component { render |> set_function_name(name) |> add_proxy @@ -33,7 +36,10 @@ pub fn component_(name name: String, render render: fn(props) -> Component) { /// Create a Redraw component, with a `name` and a `render` function. This /// component does not accept children nor props. -pub fn component__(name name: String, render render: fn() -> Component) { +pub fn component__( + name name: String, + render render: fn() -> Component, +) -> fn() -> Component { render |> set_function_name(name) |> add_empty_proxy @@ -49,9 +55,6 @@ fn convert_props(gleam_props: gleam_props) -> props /// ```gleam /// import redraw /// -/// @external(javascript, "my_library", "MyComponent") -/// fn do_my_component(props: props) -> redraw.Component -/// /// pub type MyComponentProps { /// MyComponentProps( /// first_prop: Bool, @@ -59,14 +62,17 @@ fn convert_props(gleam_props: gleam_props) -> props /// ) /// } /// -/// pub fn my_component() -> fn(MyComponentProps) -> redraw.Component { +/// @external(javascript, "my_library", "MyComponent") +/// fn do_my_component(props: MyComponentProps) -> redraw.Component +/// +/// pub fn my_component() -> fn(MyComponentProps, List(Component)) -> redraw.Component { /// redraw.to_component("MyComponent", do_my_component) /// } /// ``` pub fn to_component( name name: String, component render: fn(props) -> Component, -) -> fn(gleam_props, List(Component)) -> Component { +) -> fn(props, List(Component)) -> Component { fn(props, children) { jsx(render, convert_props(props), children) } |> set_function_name(name) } @@ -78,9 +84,6 @@ pub fn to_component( /// ```gleam /// import redraw /// -/// @external(javascript, "my_library", "MyComponent") -/// fn do_my_component(props: props) -> redraw.Component -/// /// pub type MyComponentProps { /// MyComponentProps( /// first_prop: Bool, @@ -88,6 +91,9 @@ pub fn to_component( /// ) /// } /// +/// @external(javascript, "my_library", "MyComponent") +/// fn do_my_component(props: MyComponentProps) -> redraw.Component +/// /// pub fn my_component() -> fn(MyComponentProps) -> redraw.Component { /// redraw.to_component_("MyComponent", do_my_component) /// } @@ -95,65 +101,58 @@ pub fn to_component( pub fn to_component_( name name: String, component render: fn(props) -> Component, -) -> fn(gleam_props) -> Component { +) -> fn(props) -> Component { fn(props) { jsx(render, convert_props(props), Nil) } |> set_function_name(name) } -/// Create a Redraw component with children with forwarded ref. Take a look at -/// +/// Create a Redraw component with children with forwarded ref. \ /// [Documentation](https://fr.react.dev/reference/react/forwardRef) pub fn forward_ref( name name: String, render render: fn(props, Ref(ref), List(Component)) -> Component, -) { +) -> fn(props, Ref(ref), List(Component)) -> Component { render |> set_function_name(name) |> add_children_forward_ref } -/// Create a Redraw component without children with forwarded ref. Take a look at -/// +/// Create a Redraw component without children with forwarded ref. \ /// [Documentation](https://react.dev/reference/react/forwardRef) pub fn forward_ref_( name name: String, render render: fn(props, Ref(ref)) -> Component, -) { +) -> fn(props, Ref(ref)) -> Component { render |> set_function_name(name) |> add_forward_ref } -/// Memoizes a Redraw component with children. -/// +/// Memoizes a Redraw component with children. \ /// [Documentation](https://react.dev/reference/react/memo) @external(javascript, "react", "memo") pub fn memo( component: fn(props, List(Component)) -> Component, ) -> fn(props, List(Component)) -> Component -/// Memoizes a Redraw component without children. -/// +/// Memoizes a Redraw component without children. \ /// [Documentation](https://react.dev/reference/react/memo) @external(javascript, "react", "memo") pub fn memo_(component: fn(props) -> Component) -> fn(props) -> Component // Components -/// Strict Mode should be enabled during development. -/// +/// Strict Mode should be enabled during development. \ /// [Documentation](https://react.dev/reference/react/StrictMode) @external(javascript, "./redraw.ffi.mjs", "strictMode") pub fn strict_mode(children: List(Component)) -> Component -/// Fragment allow to group children, without creating a node in the DOM. -/// +/// Fragment allow to group children, without creating a node in the DOM. \ /// [Documentation](https://react.dev/reference/react/Fragment) @external(javascript, "./redraw.ffi.mjs", "fragment") pub fn fragment(children: List(Component)) -> Component -/// Profile allows to measure code performance for a component tree. -/// +/// Profile allows to measure code performance for a component tree. \ /// [Documentation](https://react.dev/reference/react/Profiler) @external(javascript, "./redraw.ffi.mjs", "strictMode") pub fn profiler(children: List(Component)) -> Component @@ -163,8 +162,7 @@ pub type Suspense { } /// Suspense allow to display a fallback content while waiting for children to -/// finish loading. -/// +/// finish loading. \ /// [Documentation](https://fr.react.dev/reference/react/Suspense) @external(javascript, "./redraw.ffi.mjs", "fragment") pub fn suspense(props: Suspense, children: List(Component)) -> Component @@ -172,64 +170,54 @@ pub fn suspense(props: Suspense, children: List(Component)) -> Component // Hooks /// Let you cache a function definition between re-renders. -/// `dependencies` should be a tuple. -/// +/// `dependencies` should be a tuple. \ /// [Documentation](https://react.dev/reference/react/useCallback) @external(javascript, "react", "useCallback") pub fn use_callback(fun: function, dependencies: dependencies) -> function -/// Let you add a label to a custom Hook in React DevTools. -/// +/// Let you add a label to a custom Hook in React DevTools. \ /// [Documentation](https://react.dev/reference/react/useDebugValue) @external(javascript, "react", "useDebugValue") pub fn use_debug_value(value: a) -> Nil /// Let you add a label to a custom Hook in React DevTools, but allow to format -/// it before. -/// +/// it before. \ /// [Documentation](https://react.dev/reference/react/useDebugValue) @external(javascript, "react", "useDebugValue") pub fn use_debug_value_(value: a, formatter: fn(a) -> String) -> Nil -/// Let you defer updating a part of the UI. -/// +/// Let you defer updating a part of the UI. \ /// [Documentation](https://react.dev/reference/react/useDeferredValue) @external(javascript, "react", "useDeferredValue") pub fn use_deferred_value(value: a) -> a -/// Let you synchronize a component with an external system. -/// +/// Let you synchronize a component with an external system. \ /// [Documentation](https://react.dev/reference/react/useEffect) @external(javascript, "react", "useEffect") pub fn use_effect(value: fn() -> Nil, dependencies: a) -> Nil /// Let you synchronize a component with an external system. Allow to return -/// a cleanup function. -/// +/// a cleanup function. \ /// [Documentation](https://react.dev/reference/react/useEffect) @external(javascript, "react", "useEffect") pub fn use_effect_(value: fn() -> fn() -> Nil, dependencies: a) -> Nil -/// Version of useEffect that fires before the browser repaints the screen. -/// +/// Version of useEffect that fires before the browser repaints the screen. \ /// [Documentation](https://react.dev/reference/react/useLayoutEffect) @external(javascript, "react", "useLayoutEffect") pub fn use_layout_effect(value: fn() -> Nil, dependencies: a) -> Nil -/// Generate unique IDs that can be passed to accessibility attributes. -/// +/// Generate unique IDs that can be passed to accessibility attributes. \ /// [Documentation](https://react.dev/reference/react/useId) @external(javascript, "react", "useId") pub fn use_id() -> String -/// Let you cache the result of a calculation between re-renders. -/// +/// Let you cache the result of a calculation between re-renders. \ /// [Documentation](https://react.dev/reference/react/useMemo) @external(javascript, "react", "useMemo") pub fn use_memo(calculate_value: fn() -> a, dependencies: b) -> a -/// Let you add a [reducer](https://react.dev/learn/extracting-state-logic-into-a-reducer) to your component. -/// +/// Let you add a [reducer](https://react.dev/learn/extracting-state-logic-into-a-reducer) to your component. \ /// [Documentation](https://react.dev/reference/react/useReducer) @external(javascript, "react", "useReducer") pub fn use_reducer( @@ -238,8 +226,7 @@ pub fn use_reducer( ) -> #(state, fn(action) -> Nil) /// Let you add a [reducer](https://react.dev/learn/extracting-state-logic-into-a-reducer) to your component. -/// Allow to initialize the store in a custom way. -/// +/// Allow to initialize the store in a custom way. \ /// [Documentation](https://react.dev/reference/react/useReducer) @external(javascript, "react", "useReducer") pub fn use_reducer_( @@ -248,36 +235,31 @@ pub fn use_reducer_( init: fn(initializer) -> state, ) -> #(state, fn(action) -> Nil) -/// Let you add a [state variable](https://react.dev/learn/state-a-components-memory) to your component. -/// +/// Let you add a [state variable](https://react.dev/learn/state-a-components-memory) to your component. \ /// [Documentation](https://react.dev/reference/react/useState) @external(javascript, "react", "useState") pub fn use_state(initial_value: a) -> #(a, fn(a) -> Nil) /// Let you add a [state variable](https://react.dev/learn/state-a-components-memory) to your component. -/// Give an `updater` function instead of a state setter. -/// +/// Give an `updater` function instead of a state setter. \ /// [Documentation](https://react.dev/reference/react/useState) @external(javascript, "react", "useState") pub fn use_state_(initial_value: a) -> #(a, fn(fn(a) -> a) -> Nil) /// Let you add a [state variable](https://react.dev/learn/state-a-components-memory) to your component. -/// Allow to create the initial value in a lazy way. -/// +/// Allow to create the initial value in a lazy way. \ /// [Documentation](https://react.dev/reference/react/useState) @external(javascript, "react", "useState") pub fn use_lazy_state(initial_value: fn() -> a) -> #(a, fn(a) -> Nil) /// Let you add a [state variable](https://react.dev/learn/state-a-components-memory) to your component. /// Allow to create the initial value in a lazy way. -/// Give an `updater` function instead of a state setter. -/// +/// Give an `updater` function instead of a state setter. \ /// [Documentation](https://react.dev/reference/react/useState) @external(javascript, "react", "useState") pub fn use_lazy_state_(initial_value: fn() -> a) -> #(a, fn(fn(a) -> a) -> Nil) -/// Let you update the state without blocking the UI. -/// +/// Let you update the state without blocking the UI. \ /// [Documentation](https://react.dev/reference/react/useTransition) @external(javascript, "react", "useTransition") pub fn use_transition() -> #(Bool, fn() -> Nil) @@ -286,8 +268,7 @@ pub fn use_transition() -> #(Bool, fn() -> Nil) /// A Ref is a mutable data stored in React, persisted across renders. /// They allow to keep track of a DOM node, a component data, or to store a -/// mutable variable in the component, outside of every component lifecycle. -/// +/// mutable variable in the component, outside of every component lifecycle. \ /// [Documentation](https://react.dev/learn/referencing-values-with-refs) pub type Ref(a) @@ -303,10 +284,9 @@ pub fn get_current(from ref: Ref(a)) -> a /// Most used ref you'll want to create. They're automatically created to `None`, /// and can be passed to `attribute.ref` or `use_imperative_handle`. /// You probably don't want the ref value to be anything than `Option(a)`, unless -/// you have really strong reasons. -/// +/// you have really strong reasons. \ /// [Documentation](https://react.dev/reference/react/useRef) -pub fn use_ref() { +pub fn use_ref() -> Ref(Option(a)) { use_ref_(option.None) } @@ -314,25 +294,26 @@ pub fn use_ref() { /// Use `use_ref` if you're trying to acquire a reference to a child or to a /// component. Use `use_ref_` when you want to keep track of a data, like if /// you're doing some side-effects, in conjuction with `get_current` and -/// `set_current`. -/// +/// `set_current`. \ /// [Documentation](https://react.dev/reference/react/useRef) @external(javascript, "react", "useRef") pub fn use_ref_(initial_value: a) -> Ref(a) /// Let you customize the handle exposed as a [ref](https://react.dev/learn/manipulating-the-dom-with-refs). /// Use `use_imperative_handle` when you want to customize the data stored in -/// a ref. It's mostly used in conjuction with `forward_ref`. -/// +/// a ref. It's mostly used in conjuction with `forward_ref`. \ /// [Documentation](https://react.dev/reference/react/useImperativeHandle) -pub fn use_imperative_handle(ref, handler, dependencies) { +pub fn use_imperative_handle( + ref: Ref(Option(a)), + handler: fn() -> a, + dependencies: b, +) -> Nil { use_imperative_handle_(ref, fn() { option.Some(handler()) }, dependencies) } /// Let you customize the handle exposed as a [ref](https://react.dev/learn/manipulating-the-dom-with-refs). /// Use `use_imperative_handle` by default, unless you really know what you're -/// doing. -/// +/// doing. \ /// [Documentation](https://react.dev/reference/react/useImperativeHandle) @external(javascript, "react", "useImperativeHandle") pub fn use_imperative_handle_( @@ -343,26 +324,22 @@ pub fn use_imperative_handle_( // Contexts -/// Pass data without props drilling. -/// +/// Pass data without props drilling. \ /// [Documentation](https://react.dev/learn/passing-data-deeply-with-context) pub type Context(a) -/// Let you read and subscribe to [context](https://react.dev/learn/passing-data-deeply-with-context) from your component. -/// +/// Let you read and subscribe to [context](https://react.dev/learn/passing-data-deeply-with-context) from your component. \ /// [Documentation](https://react.dev/reference/react/useContext) @external(javascript, "react", "useContext") pub fn use_context(context: Context(a)) -> a -/// Let you create a [context](https://react.dev/learn/passing-data-deeply-with-context) that components can provide or read. -/// +/// Let you create a [context](https://react.dev/learn/passing-data-deeply-with-context) that components can provide or read. \ /// [Documentation](https://react.dev/reference/react/createContext) @deprecated("Use redraw/create_context_ instead. redraw/create_context will be removed in 2.0.0. Unusable right now, due to how React handles Context.") @external(javascript, "react", "createContext") pub fn create_context(default_value default_value: Option(a)) -> Context(a) -/// Wrap your components into a context provider to specify the value of this context for all components inside. -/// +/// Wrap your components into a context provider to specify the value of this context for all components inside. \ /// [Documentation](https://react.dev/reference/react/createContext#provider) @external(javascript, "./context.ffi.mjs", "contextProvider") pub fn provider( @@ -516,15 +493,13 @@ pub fn context(name: String, default_value: fn() -> a) -> Context(a) { } // API -// -/// Test helper to apply pending React updates before making assertions. -/// + +/// Test helper to apply pending React updates before making assertions. \ /// [Documentation](https://react.dev/reference/react/act) @external(javascript, "react", "act") pub fn act(act_fn: fn() -> Promise(Nil)) -> Promise(Nil) -/// Let you update the state without blocking the UI. -/// +/// Let you update the state without blocking the UI. \ /// [Documentation](https://react.dev/reference/react/startTransition) @external(javascript, "react", "startTransition") pub fn start_transition(scope scope: fn() -> Nil) -> Nil @@ -552,7 +527,7 @@ pub fn keyed( } // FFI -// Those functions are used internal by Redraw, to setup things correctly. +// Those functions are used internally by Redraw, to setup things correctly. // They should not be accessible from the outside world. @external(javascript, "./redraw.ffi.mjs", "jsx") diff --git a/redraw/src/redraw/attribute.gleam b/redraw/src/redraw/attribute.gleam index 8966a11..6ebcca4 100644 --- a/redraw/src/redraw/attribute.gleam +++ b/redraw/src/redraw/attribute.gleam @@ -1,33 +1,51 @@ +//// Implementation for HTML and SVG attributes usable in React and in browser. +//// Contrarily to Lustre, every attributes can take arbitrary data, because +//// they're directly bind in the underlying component's props. +//// +//// All available attributes can be found in the +//// [React.dev](https://react.dev/reference/react-dom/components/common#common) +//// documentation for detailed information, as well as on +//// [MDN](https://developer.mozilla.org/docs/Web/API/Element). + import gleam/option import gleam/string import redraw import redraw/internals/attribute +/// Attribute linked on an HTML or SVG node. Think about like a `prop` in React. pub type Attribute = attribute.Attribute pub const attribute = attribute.attribute +/// [Documentation](https://developer.mozilla.org/docs/Web/API/HTMLAnchorElement/href) pub fn href(url: String) { - attribute.attribute("href", url) + attribute("href", url) } +/// [Documentation](https://developer.mozilla.org/docs/Web/API/HTMLAnchorElement/target) pub fn target(value: String) { - attribute.attribute("target", value) + attribute("target", value) } +/// [Documentation](https://developer.mozilla.org/docs/Web/API/HTMLMediaElement/src) pub fn src(value: String) { - attribute.attribute("src", value) + attribute("src", value) } +/// [Documentation](https://developer.mozilla.org/docs/Web/HTML/Global_attributes/class) pub fn class(value: String) { - attribute.attribute("className", value) + attribute("className", value) } +/// [Documentation](https://developer.mozilla.org/docs/Web/API/HTMLMediaElement/alt) pub fn alt(value: String) { - attribute.attribute("alt", value) + attribute("alt", value) } +/// Inner HTML data are HTML that will not be verified sanitized. +/// Be careful when using it. You should almost always prefer to use +/// `redraw/element/html`. pub type InnerHTML /// The `inner_html` data should be created as close to where the HTML is @@ -35,8 +53,7 @@ pub type InnerHTML /// code is explicitly marked as such, and that only variables that you expect /// to contain HTML are passed to `dangerously_set_inner_html`. It is not /// recommended to create the object inline like -/// `html.div([attribute.dangerously_set_inner_html(attribute.inner_html(markup))], [])` -/// +/// `html.div([attribute.dangerously_set_inner_html(attribute.inner_html(markup))], [])` \ /// [Documentation](https://react.dev/reference/react-dom/components/common#dangerously-setting-the-inner-html) @external(javascript, "../redraw.ffi.mjs", "innerHTML") pub fn inner_html(html: String) -> InnerHTML @@ -44,11 +61,10 @@ pub fn inner_html(html: String) -> InnerHTML /// Overrides the innerHTML property of the DOM node and displays the passed /// HTML inside. This should be used with extreme caution! If the HTML inside /// isn’t trusted (for example, if it’s based on user data), you risk -/// introducing an XSS vulnerability. -/// +/// introducing an XSS vulnerability. \ /// [Documentation](https://react.dev/reference/react-dom/components/common#dangerously-setting-the-inner-html) pub fn dangerously_set_inner_html(inner_html: InnerHTML) { - attribute.attribute("dangerouslySetInnerHTML", inner_html) + attribute("dangerouslySetInnerHTML", inner_html) } /// A ref object from `redraw.use_ref`. Your ref will be filled with the DOM @@ -56,323 +72,419 @@ pub fn dangerously_set_inner_html(inner_html: InnerHTML) { /// forced to use an optional type here. Because when using this function, you /// want to get a reference from a real DOM node, meaning at the initialization /// of the reference, you won't have any data. Use `ref_` when you want full -/// control over the ref you send to the Component. +/// control over the ref you send to the Component. \ +/// [Documentation](https://react.dev/reference/react-dom/components/common#manipulating-a-dom-node-with-a-ref) pub fn ref(ref: redraw.Ref(option.Option(a))) { - attribute.attribute("ref", fn(dom_ref) { - redraw.set_current(ref, option.Some(dom_ref)) - }) + attribute("ref", fn(dom_ref) { redraw.set_current(ref, option.Some(dom_ref)) }) } /// A ref callback function. The callback will be provided with the DOM element /// for this node. Use this function to get control on the ref provided by the -/// DOM node or the component. +/// DOM node or the component. \ +/// [Documentation](https://react.dev/reference/react-dom/components/common#manipulating-a-dom-node-with-a-ref) pub fn ref_(ref: fn(a) -> Nil) { - attribute.attribute("ref", ref) + attribute("ref", ref) } +/// If `True`, suppresses the warning that React shows for elements that both +/// have `children` and `content_editable(True)` (which normally do not work +/// together). Use this if you’re building a text input library that manages +/// the `contentEditable` content manually. pub fn suppress_content_editable_warning(value: Bool) { - attribute.attribute("suppressContentEditableWarning", value) + attribute("suppressContentEditableWarning", value) } +/// If you use [server rendering](https://react.dev/reference/react-dom/server), +/// normally there is a warning when the server and the client render different +/// content. In some rare cases (like timestamps), it is very hard or impossible +/// to guarantee an exact match. If you set suppressHydrationWarning to true, +/// React will not warn you about mismatches in the attributes and the content +/// of that element. It only works one level deep, and is intended to be used +/// as an escape hatch. Don’t overuse it. +/// [Read about suppressing hydration errors.](https://react.dev/reference/react-dom/client/hydrateRoot#suppressing-unavoidable-hydration-mismatch-errors) pub fn suppress_hydration_warning(value: Bool) { - attribute.attribute("suppressHydrationWarning", value) + attribute("suppressHydrationWarning", value) } @external(javascript, "../redraw.ffi.mjs", "convertStyle") fn convert_style(styles: List(#(String, String))) -> a +/// [Documentation](https://developer.mozilla.org/docs/Web/HTML/Global_attributes/style) pub fn style(styles: List(#(String, String))) { - attribute.attribute("style", convert_style(styles)) + attribute("style", convert_style(styles)) } /// Set aria attribute on the node. Should be used like `aria("valuenow", "75")`. pub fn aria(key: String, value: String) { - attribute.attribute("aria-" <> key, value) + attribute("aria-" <> key, value) } +/// [Documentation](https://developer.mozilla.org/docs/Web/HTML/Global_attributes/accesskey) pub fn access_key(value: String) { - attribute.attribute("accessKey", value) + attribute("accessKey", value) } +/// [Documentation](https://developer.mozilla.org/docs/Web/HTML/Global_attributes/autocapitalize) pub fn auto_capitalize(value: String) { - attribute.attribute("autoCapitalize", value) + attribute("autoCapitalize", value) } -/// Alias of `class`. +/// Alias of `class`. \ +/// [Documentation](https://developer.mozilla.org/docs/Web/HTML/Global_attributes/class) pub fn class_name(value: String) { - attribute.attribute("className", value) + attribute("className", value) } /// If true, the browser lets the user edit the rendered element directly. /// This is used to implement rich text input libraries like Lexical. React /// warns if you try to pass React children to an element with /// `content_editable(True)` because React will not be able to update its content -/// after user edits. +/// after user edits. \ +/// [Documentation](https://developer.mozilla.org/docs/Web/API/HTML/Global_attributes/contenteditable) pub fn content_editable(value: Bool) { - attribute.attribute("contentEditable", value) + attribute("contentEditable", value) } /// Data attributes let you attach some string data to the element, for example /// `data("fruit", "banana")`. In React, they are not commonly used because you -/// would usually read data from props or state instead. +/// would usually read data from props or state instead. \ +/// [Documentation](https://developer.mozilla.org/docs/Web/HTML/Global_attributes/data-*) pub fn data(key: String, value: String) { - attribute.attribute("data-" <> key, value) + attribute("data-" <> key, value) } +/// Directionality of an element text. pub type Dir { Ltr Rtl } -/// Specifies the text direction of the element. +/// Specifies the text direction of the element. \ +/// [Documentation](https://developer.mozilla.org/docs/Web/HTML/Global_attributes/dir) pub fn dir(value: Dir) { let value = case value { Ltr -> "ltr" Rtl -> "rtl" } - attribute.attribute("dir", value) + attribute("dir", value) } -/// Specifies whether the element is draggable. Part of HTML Drag and Drop API. +/// Specifies whether the element is draggable. Part of HTML Drag and Drop API. \ +/// [Documentation](https://developer.mozilla.org/docs/Web/HTML/Global_attributes/draggable) pub fn draggable(value: Bool) { - attribute.attribute("draggable", value) + attribute("draggable", value) } -/// Specifies which action to present for the enter key on virtual keyboards. +/// Specifies which action to present for the enter key on virtual keyboards.\ +/// [Documentation](https://developer.mozilla.org/docs/Web/HTML/Global_attributes/enterkeyhint) pub fn enter_key_hint(value: String) { - attribute.attribute("enterKeyHint", value) + attribute("enterKeyHint", value) } /// For