npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

matsuri-forms-sdk

v2.0.0

Published

<!-- vscode-markdown-toc -->

Downloads

1,454

Readme

matsuri-forms-sdk

Installation

yarn add matsuri-forms-sdk matsuri-hooks

How to use

useMatsuriForms

useMatsuriFormsは、matsuri-formsを利用したフォームを扱いやすくするためのものです。 これはHeadlessなため、見た目は自分で作るか、matsuri-forms-sdk/matsuri-uiを利用する必要があります。

import { useMatsuriForms, MatsuriFormsQuestionProvider, MatsuriFormsQuestion } from "matsuri-forms-sdk"
import { SelectQuestion, MultipleTextQuestion, TextQuestion } from "matsuri-forms-sdk/matsuri-ui"
import { Button, useAlert } from "matsuri-ui"
const Form = ({ formId }:{ formId: string }) => {
  const { questions, submit, errors, validate, isSubmitting, title } = useMatsuriForms(
    formId
    {
      dev: process.env.NODE_ENV !== "production",
    },
  );
  const { throwAlert } = useAlert()

  return (
    <div
      css={css`
        display: grid;
        gap: 24px;
      `}
    >
      <header>
        <Typography variant="h2">
          {title}
        </Typography>
      </header>
      <form
        onSubmit={async (event) => {
          event.preventDefault();
          const { errors } = validate(event.currentTarget);
          if (errors) {
            return
          }

          const { error } = await submit(event.currentTarget);

          throwAlert(error, {
            errorMessage: {
              reason: "サーバー側のエラーの可能性があります。",
              action:
                "しばらく時間を空けて試すか、開発チームへお問い合わせください。",
              happend: "フィードバックの送信に失敗しました。",
            },
          });
        }}
      >
        <MatsuriFormsQuestionProvider
          renderSelect={SelectQuestion}
          renderMultilineText={MultipleTextQuestion}
          renderText={TextQuestion}
        >
          {questions.map((question) => {
            return (
              <MatsuriFormsQuestion
                error={errors[question.id]}
                {...question}
                key={question.id}
              />
            );
          })}
        </MatsuriFormsQuestionProvider>
        <Button
          variant="filled"
          disabled={isSubmitting}
          color="primary"
        >
          送信する
        </Button>
      </form>
    </div>
  );
};

useSurveyForm

useSurveyForm、matsuri-formsを利用してアンケート調査などを行うためのものです。 これはUIにmatsuri-uiを利用しています。 matsuri-uiを利用したコードは、すべてmatsuri-forms-sdk/matsuri-uiから利用します。

import {
  SurveyFormProvider,
  useSurveyForm,
} from "matsuri-forms-sdk/matsuri-ui";
import { Button } from "matsuri-ui";

const Page = () => {
  const survey = useSurveyForm({
    formId: "01J151HQRHBKXJPH5K4T435AMF",
  });

  return (
    <Button
      onClick={async () => {
        if (await survey()) {
          console.log("Happy day!");
        } else {
          console.log("Sad day!");
        }
      }}
    >
      Tap me!
    </Button>
  );
};

//
<SurveyFormProvider>
  <Page />
</SurveyFormProvider>;

Basic Usage

useSurveyFormとsurveyを同じ引数を取ります。 状況に合わせて、適した方を利用してください。useSurveyFormの引数はsurveyの引数で上書きされます。

const survey = useSurveyForm({ formId: "01J151HQRHBKXJPH5K4T435AMF" });

if (await survey()) {
  console.log("Happy day!");
} else {
  console.log("Sad day!");
}
const survey = useSurveyForm();

await survey({ formId: "01J151HQRHBKXJPH5K4T435AMF" });
await survey({ formId: "02J151HQRHBKXJPH5K4T435AMF" });

Use dev forms

開発環境のフォームを利用する場合は次のようにします。

const survey = useSurveyForm({
  formId: "01J151HQRHBKXJPH5K4T435AMF",
  dev: true,
});
const survey = useSurveyForm({ dev: true });
await survey({ formId: "01J151HQRHBKXJPH5K4T435AMF" });

Custom success messages

await survey({
  formId: "01J151HQRHBKXJPH5K4T435AMF",
  ignoreSuccessMessage: true,
});
await survey({
  formId: "01J151HQRHBKXJPH5K4T435AMF",
  successMessage: "Thanks!",
});

Set defaultValues

await survey({
  defaultValues: {
    "1904a18ddb112e": "John Doe",
    "01J151MW4QG3A91FHBF37RJ6CY": ["5"],
    "01J151K2RMKMVEB3ZPHXG7MXKB": "素晴らしいサービスです!",
  },
});

Hidden specified questions

await survey({
  hiddenQuestionIds: ["1904a18ddb112e"],
});