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

Improve styles in playground's Live panel #201

Open
feihong opened this issue Oct 25, 2024 · 0 comments
Open

Improve styles in playground's Live panel #201

feihong opened this issue Oct 25, 2024 · 0 comments

Comments

@feihong
Copy link
Collaborator

feihong commented Oct 25, 2024

Add some basic styles to the Live panel so that simple component examples like this don't need extra styles added to make them legible.

module Speech = {
  type utterance;

  [@mel.new]
  external makeUtterance: string => utterance = "SpeechSynthesisUtterance";

  external speak: utterance => unit = "speechSynthesis.speak";
};

module App = {
  [@react.component]
  let make = () =>
    <button
      onClick={_ =>
        "Hello ReasonReact" |> Speech.makeUtterance |> Speech.speak
      }>
      {React.string("Say hello")}
    </button>;
};

let () =
  switch (ReactDOM.querySelector("#preview")) {
  | None =>
    Js.log("Failed to start React: couldn't find the #preview element")
  | Some(root) =>
    let root = ReactDOM.Client.createRoot(root);
    ReactDOM.Client.render(root, <App />);
  };

In Playground, the above snippet renders like this:

image

In order to make it render in reasonable way, I have to add extra styles to the button:

module App = {
  [@react.component]
  let make = () =>
    <button
      style={ReactDOM.Style.make(
        ~fontSize="1em",
        ~border="1px solid white",
        ~borderRadius="0.5em",
        ~padding="1em",
        (),
      )}
      onClick={_ =>
        "Hello ReasonReact" |> Speech.makeUtterance |> Speech.speak
      }>
      {React.string("Say hello")}
    </button>;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant