-
-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4847935
commit 261ae2b
Showing
7 changed files
with
239 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import { Meta, Story } from "@storybook/addon-docs"; | ||
import { FormAutoFocus } from "./formautofocus.stories.js"; | ||
|
||
<Meta title="Patterns/FormAutoFocus" /> | ||
|
||
# Formautofocus pattern. | ||
|
||
Automatically set the focus on a form input field. | ||
|
||
## Configuration | ||
|
||
```md | ||
| Option | Type | Default | Description | | ||
| :-------: | :----: | :---------------------------------------------: | :---------: | | ||
| condition | string | "div.error" | | | ||
| target | string | "div.error :input:not(.formTabs):visible:first" | | | ||
| always | string | ":input:not(.formTabs):visible:first" | | | ||
``` | ||
|
||
## Examples | ||
|
||
### Form Autofocus | ||
|
||
<br /> | ||
<Story name="Form AutoFocus" of={FormAutoFocus} /> | ||
|
||
```html | ||
<h4>Form without Autofocus</h4> | ||
<form> | ||
<div class="error"> | ||
<input | ||
type="text" | ||
placeholder="should not be focused" | ||
name="in_other_form_should_not_be_focused" | ||
/> | ||
</div> | ||
</form> | ||
<h4>Form with Autofocus</h4> | ||
<form class="pat-formautofocus"> | ||
<div> | ||
<input | ||
type="text" | ||
placeholder="should not be focused" | ||
name="a_should_not_be_focused" | ||
class="formTabs" | ||
/> | ||
<input | ||
type="text" | ||
placeholder="should not be focused" | ||
name="b_should_not_be_focused" | ||
/> | ||
</div> | ||
<div class="error"> | ||
<input | ||
type="text" | ||
placeholder="should not be focused" | ||
name="c_should_not_be_focused" | ||
class="formTabs" | ||
/> | ||
<input type="text" name="d_should_be_focused" /> | ||
</div> | ||
</form> | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import $ from "jquery"; | ||
import { RenderHTML } from "./setup.js"; | ||
import FormAutofocus from "../../src/pat/formautofocus/formautofocus.js"; | ||
|
||
export default { | ||
title: "Patterns/FormAutoFocus", | ||
argTypes: { | ||
error: { | ||
control: "boolean", | ||
description: "Toggle to add an error state", | ||
table: { | ||
category: "Behavior", | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
const getFormAutoFocus = ({ error }) => ` | ||
<h4>Form without Autofocus</h4> | ||
<form> | ||
<div class="error"> | ||
<input | ||
type="text" | ||
placeholder="should not be focused" | ||
name="in_other_form_should_not_be_focused" | ||
/> | ||
</div> | ||
</form> | ||
<br /> | ||
<h4>Form with Autofocus</h4> | ||
<form class="pat-formautofocus"> | ||
<div> | ||
<input | ||
type="text" | ||
placeholder="should not be focused" | ||
name="a_should_not_be_focused" | ||
class="formTabs" | ||
/> | ||
<input | ||
type="text" | ||
placeholder="should not be focused" | ||
name="b_should_not_be_focused" | ||
/> | ||
</div> | ||
${ | ||
error | ||
? ` | ||
<div class="error"> | ||
<input | ||
type="text" | ||
placeholder="should not be focused" | ||
name="c_should_not_be_focused" | ||
class="formTabs" | ||
/> | ||
<input type="text" name="d_should_be_focused" /> | ||
</div>` | ||
: "" | ||
} | ||
</form> | ||
`; | ||
|
||
export const FormAutoFocus = { | ||
render: (args) => { | ||
const wrapper = RenderHTML(args, getFormAutoFocus); | ||
|
||
return wrapper; | ||
}, | ||
args: { | ||
error: true, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { Meta, Story } from "@storybook/addon-docs"; | ||
import { PasswordStrength, PasswordStrengthCustom } from "./passwordstrength.stories.js"; | ||
|
||
<Meta title="Patterns/PasswordStrength" /> | ||
|
||
# Password strength pattern. | ||
|
||
Check the strength of a password. | ||
|
||
## Configuration | ||
|
||
```md | ||
| Option | Type | Default | Description | | ||
| :----: | :----: | :-----: | :---------------------------------------------: | | ||
| zxcvbn | string | cdnjs | Location to load zxcvbn from. Defaults to cdnjs | | ||
``` | ||
|
||
## Examples | ||
|
||
### Simple | ||
|
||
<br /> | ||
<Story name="Password Strength" of={PasswordStrength} /> | ||
|
||
```html | ||
<input type="password" class="pat-passwordstrength" /> | ||
``` | ||
|
||
### Custom zxcvbn location | ||
|
||
<br /> | ||
<Story name="Password Strength" of={PasswordStrengthCustom} /> | ||
|
||
```html | ||
<input | ||
type="password" | ||
class="pat-passwordstrength" | ||
data-pat-passwordstrength="zxcvbn: //lowe.github.io/tryzxcvbn/zxcvbn.js" | ||
/> | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import $ from "jquery"; | ||
import { RenderHTML } from "./setup.js"; | ||
import PasswordStrengthComponent from "../../src/pat/passwordstrength/passwordstrength.js"; | ||
|
||
export default { | ||
title: "Patterns/PasswordStrength", | ||
zxcvbn: { | ||
control: "text", | ||
description: "Custom URL for the zxcvbn library", | ||
table: { | ||
disable: true, | ||
}, | ||
}, | ||
}; | ||
|
||
// Simple password | ||
const getPasswordStrength = () => ` | ||
<input type="password" class="pat-passwordstrength" /> | ||
`; | ||
|
||
export const PasswordStrength = { | ||
render: () => { | ||
const wrapper = RenderHTML({}, getPasswordStrength); | ||
|
||
return wrapper; | ||
}, | ||
}; | ||
|
||
// Custom zxcvbn location | ||
const getPasswordStrengthCustom = ({ zxcvbn }) => ` | ||
<input | ||
type="password" | ||
class="pat-passwordstrength" | ||
data-pat-passwordstrength="zxcvbn: ${zxcvbn}" | ||
/> | ||
`; | ||
|
||
export const PasswordStrengthCustom = { | ||
render: (args) => RenderHTML(args, getPasswordStrengthCustom), | ||
args: { | ||
zxcvbn: "//lowe.github.io/tryzxcvbn/zxcvbn.js", | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import registry from "@patternslib/patternslib/src/core/registry"; | ||
|
||
/** | ||
* Storybook runs inside an iframe, which means we need to ensure that | ||
* Patternslib is fully initialized before rendering the HTML. | ||
* | ||
* To achieve this, the `RenderHTML` function delays rendering | ||
* so Patternslib is ready. | ||
*/ | ||
export const RenderHTML = (args, getStoryHtml) => { | ||
const wrapper = document.createElement("div"); | ||
wrapper.innerHTML = getStoryHtml(args); | ||
|
||
// Ensure PatternsLib initializes after render | ||
setTimeout(() => { | ||
registry.scan(wrapper); | ||
}, 300); | ||
|
||
return wrapper; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters