Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
batosai committed Jan 23, 2024
2 parents 00eb4e9 + 75774fa commit 90272e7
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 13 deletions.
8 changes: 5 additions & 3 deletions fractal.helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,9 @@ const jrmc = {

return option.selected ?? false
},
getLabel: (props, context = { translator: { prefix: '' } }) => {
const t = defaultT
getLabel: (props, context = { translator: { prefix: '', t: (k) => k } }) => {
const t = context.translator.t

let name = props.has('name') ? props.get('name') : ''

if (props.has('translator.prefix')) {
Expand Down Expand Up @@ -123,5 +124,6 @@ module.exports = {
getNextPageUrl: () => urls[currentPage+1].url,
}
},
flashMessages
flashMessages,
t: defaultT
}
2 changes: 1 addition & 1 deletion fractal/components/03-form/03-form-translate-labels.edge
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@jrmc.form({ error: false, translator: { prefix: 'user.' }})
@jrmc.form({ error: false, translator: { prefix: 'user.', t: (key) => t(key) }})
@jrmc.form.control({ name: 'name' })
@!jrmc.form.input({ class: 'input-bordered' })
@end
Expand Down
31 changes: 26 additions & 5 deletions fractal/components/03-form/readme.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,29 @@
# Form


| Option | value | |
|---------|------------|--------------------------------------|
| method | GET/POST | HTTP method (default POST) |
| csrf | true/false | add csrf input hidden (default true) |
| error | true/false | show errors message (default true) |
| Option | value | |
|-------------------|--------------|--------------------------------------|
| method | GET/POST | HTTP method (default POST) |
| csrf | true/false | add csrf input hidden (default true) |
| error | true/false | show errors message (default true) |
| translator | object | config for translate |
| translator.prefix | property | prefix translator |
| translator.t | property | function translate |

## Translator AdonisJS

```
{
prefix: 'user.',
t: (key) => t(key)
}
@jrmc.form({ translator: { prefix: 'user.', t: (key) => t(key) }})
@jrmc.form.control({ name: 'name' })
@!jrmc.form.input({ class: 'input-bordered' })
@end
@end
=> exec i18n helper Adonis t('user.name')
```
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@jrmc/edge-components",
"version": "1.7.0",
"version": "1.7.1",
"description": "",
"main": "build/index.js",
"repository": {
Expand Down
4 changes: 3 additions & 1 deletion src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ const obj = {

return option.selected ?? false
},
getLabel: (props, context = { translator: { prefix: '' } }, t=(k)=>k) => {
getLabel: (props, context = { translator: { prefix: '', t: (k) => k } }) => {
const t = context.translator.t

let name = props.has('name') ? props.get('name') : ''

if (props.has('translator.prefix')) {
Expand Down
2 changes: 1 addition & 1 deletion views/components/form.edge
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@inject({
object: $props.get('object'),
translator: $props.has('translator') ? $props.get('translator') : null
translator: $props.has('translator') ? $props.get('translator') : { prefix: '', t: (k) => k }
})

<form method="{{ jrmc.getMethodForm($props, 'POST') }}" {{ $props.serializeExcept(['method', 'object', 'translator']) }}>
Expand Down
2 changes: 1 addition & 1 deletion views/components/form/control.edge
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
@!jrmc.form.label({ text: $props.get('label'), class: 'cursor-pointer', for: jrmc.getId($props), required: jrmc.getRequired($props), })
@end~
@elseif($props.has('name'))~
@!jrmc.form.label({ text: jrmc.getLabel($props, $context, t ? t : k=>k ), class: 'cursor-pointer', for: jrmc.getId($props), required: jrmc.getRequired($props), })
@!jrmc.form.label({ text: jrmc.getLabel($props, $context), class: 'cursor-pointer', for: jrmc.getId($props), required: jrmc.getRequired($props), })
@end~

{{{ await $slots.main() || '' }}}
Expand Down

0 comments on commit 90272e7

Please sign in to comment.