-
Notifications
You must be signed in to change notification settings - Fork 334
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
Update JavaScript docs #808
Conversation
|
||
You can also initialise individual components using the `data-module` attribute set on the component. If you only have one instance of a component per page, you can follow the below example to initialise it: | ||
|
||
```js |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The initialisation is dependent on the include/import method.
- If we use
import Radios from 'govuk-frontend/components/radios/radios'
we assign the exported constructor to theRadios
variable at import. - If we include the
all.js
script we need to refer the constructor from theGOVUKFrontend
global variablevar Radios = window.GOVUKFrontend.Radios
And then do the initialisation as shown below:
var $radio = document.querySelector('[data-module="radios"]')
if ($radio) {
new Radios($radio).init()
}
dcd5535
to
bb480f1
Compare
bb480f1
to
b3cabda
Compare
b3cabda
to
db7535c
Compare
db7535c
to
88a3456
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking really good. Some comments, that maybe we could give default recommendations rather than letting people decide. This'd make it easier for copy and paste folks. Happy to talk it through in person.
@@ -55,7 +52,7 @@ your Sass file: | |||
@import "node_modules/govuk-frontend/components/button/button"; | |||
``` | |||
|
|||
#### Optional: Resolving import paths | |||
### Optional: Resolving SASS import paths |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SASS -> SCSS
|
||
new Button().init() | ||
#### Initialise all included components |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this would make sense to be above the other, since I imagine most people will use this by default.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could consider merging this example with the place we tell people to include a script tag.
Document including the scripts, instead of importing them, as an option. Fix out-of-date initialisation instructions. Fix some heading levels. Also remove a stray comment about FE being available to install as multiple packages.
ce75e9f
to
821f2b6
Compare
Thanks for the IRL @NickColley. Could you check you're happy with the changes made before I merge this 🙂 |
Thanks Hanna, I think this'll help people a lot |
This PR:
include
orimport
install as multiple packages
src/all.js
Trello card