Skip to content

Commit

Permalink
feat(doc): add guide about form
Browse files Browse the repository at this point in the history
  • Loading branch information
dpellier committed Nov 28, 2024
1 parent fe58535 commit 03d24b8
Show file tree
Hide file tree
Showing 5 changed files with 336 additions and 20 deletions.
8 changes: 4 additions & 4 deletions packages/examples/react-webpack/src/app/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
import React, { type ReactElement } from 'react';
import styles from './app.scss';
// import { Gallery } from './components/gallery/Gallery';
// import { FormFormik } from './components/formFormik/FormFormik';
import { FormHookForm } from './components/formHookForm/FormHookForm';
import { FormFormik } from './components/formFormik/FormFormik';
// import { FormHookForm } from './components/formHookForm/FormHookForm';
// import { FormNative } from './components/formNative/FormNative';
// import { TestModal } from './components/testModal/TestModal';
// import { TestSelect } from './components/testSelect/TestSelect';
Expand All @@ -14,8 +14,8 @@ function App(): ReactElement {
return (
<div className={ styles.app }>
{/*<Gallery />*/}
{/*<FormFormik />*/}
<FormHookForm />
<FormFormik />
{/*<FormHookForm />*/}
{/*<FormNative />*/}
{/*<QueryClientProvider client={queryClient}>*/}
{/* <TestSelect />*/}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,20 @@
import { ODS_INPUT_TYPE } from '@ovhcloud/ods-components';
import { OdsButton, OdsCheckbox, OdsDatepicker, OdsInput, OdsPassword, OdsPhoneNumber, OdsQuantity, OdsRadio, OdsSelect, OdsSwitch, OdsSwitchItem, OdsTextarea, OdsTimepicker } from '@ovhcloud/ods-components/react';
import React, { type ReactElement, useRef, useState } from 'react';
import React, { type FormEvent, type ReactElement, useRef, useState } from 'react';
import styles from './formNative.scss';

function FormNative(): ReactElement {
const formRef = useRef<HTMLFormElement>(null);
const [areAllRequired, setAreAllRequired] = useState(false);

async function onSubmit(e: any) {
function onSubmit(e: FormEvent) {
e.preventDefault();
e.stopPropagation();

const formData = new FormData(formRef.current!);

for (const [key, value] of formData) {
console.log(`${key}: ${value}`)
}

return false;
}

function onAllRequiredToggle() {
Expand Down
22 changes: 11 additions & 11 deletions packages/examples/vanilla-webpack/src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,17 @@
</form>

<script>
// const formElement = document.querySelector('form');
//
// formElement.addEventListener('submit', (e) => {
// e.preventDefault();
//
// const formData = new FormData(formElement)
//
// for (const [key, value] of formData) {
// console.log(`${key}: ${value}`)
// }
// });
const formElement = document.querySelector('form');

formElement.addEventListener('submit', (e) => {
// e.preventDefault();

const formData = new FormData(formElement)

for (const [key, value] of formData) {
console.log(`${key}: ${value}`)
}
});
</script>
</body>
</html>
3 changes: 3 additions & 0 deletions packages/storybook/.storybook/preview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,9 @@ const preview: Preview = {
'Style Customization',
'*',
],
'Guides', [
'*',
],
],
'ODS Components', [
'Gallery',
Expand Down
Loading

0 comments on commit 03d24b8

Please sign in to comment.