Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

49 changes: 25 additions & 24 deletions packages/docs/.storybook/custom/css-variables.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,38 +20,39 @@ export function CssVariables({cssVariables}: {cssVariables?: Record<string, Vari
return {...obj, [lol[0].trim()]: lol[1].trim()};
}, {}) as any
}));

const {global, common, local} = (cssVariables ?? meta.preparedMeta.parameters?.cssVariables ?? {}) as Record<
string,
VariableDefinitions
>;

function getTable(name: string, variables: VariableDefinitions) {
const rows = Object.keys(variables).reduce((obj, name) => {
const value = getComputedStyle(document.documentElement).getPropertyValue(name);
const defaultValue = (dark && variables[name].dark) || variables[name].main;
const rows = variables
? Object.keys(variables).reduce((obj, name) => {
const value = getComputedStyle(document.documentElement).getPropertyValue(name);
const defaultValue = (dark && variables[name].dark) || variables[name].main;

let computedDefaultValue = "";
if (ref) {
ref.style.setProperty("--defaultValue", defaultValue);
computedDefaultValue = getComputedStyle(ref).getPropertyValue("--defaultValue");
}
let computedDefaultValue = "";
if (ref) {
ref.style.setProperty("--defaultValue", defaultValue);
computedDefaultValue = getComputedStyle(ref).getPropertyValue("--defaultValue");
}

return {
...obj,
[name]: {
name,
type: {
required:
computedDefaultValue.replaceAll(String.raw`0\.`, ".") !==
value.replaceAll(String.raw`0\.`, ".")
},
table: {type: {summary: value}},
defaultValue: {summary: defaultValue},
control: {type: "text"}
}
};
}, {});
return {
...obj,
[name]: {
name,
type: {
required:
computedDefaultValue.replaceAll(String.raw`0\.`, ".") !==
value.replaceAll(String.raw`0\.`, ".")
},
table: {type: {summary: value}},
defaultValue: {summary: defaultValue},
control: {type: "text"}
}
};
}, {})
: {};

return Object.keys(rows).length ? (
<>
Expand Down
52 changes: 52 additions & 0 deletions packages/docs/model/forms.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import type {Meta} from "@storybook/react";
import type {StoryObj} from "@storybook/react-vite";
import {observer} from "mobx-react";
import z from "zod";

import {e, entity} from "@focus4/entities";
import {domain} from "@focus4/form-toolbox";
import {fieldFor, useFormNode} from "@focus4/forms";
import {makeEntityStore} from "@focus4/stores";

const LIBELLE = domain(z.string());

// Entity pour la story par défaut
const simpleStore = makeEntityStore({
simple: entity({
name: e.field(LIBELLE, f => f.label("Nom").defaultValue("Georges"))
})
});

// ============================================
// Composants pour les stories
// ============================================

const SimpleField = observer(() => {
const formNode = useFormNode(simpleStore.simple, f => f.edit(true));
return fieldFor(formNode.name);
});

const meta = {
title: "Modèle métier/Créer un formulaire",
component: SimpleField
} satisfies Meta<typeof SimpleField>;

export default meta;

type Story = StoryObj<typeof meta>;

// ============================================
// Stories
// ============================================

/**
* Exemple par défaut d'un champ texte simple en mode édition.
*/
export const Default: Story = {
tags: ["autodocs"],
render: () => {
const formNode = useFormNode(simpleStore.simple, f => f.edit(true));
return fieldFor(formNode.name);
}
};

5 changes: 4 additions & 1 deletion packages/docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
"@focus4/collections": "12.7.0",
"@focus4/core": "12.7.0",
"@focus4/forms": "12.7.0",
"@focus4/form-toolbox": "12.7.0",
"@focus4/entities": "12.7.0",
"@focus4/layout": "12.7.0",
"@focus4/stores": "12.7.0",
"@focus4/styling": "12.7.0",
Expand All @@ -30,4 +32,5 @@
"storybook": "10.1.9",
"storybook-react-i18next": "10.0.1"
}
}
}