Config Provider is used for providing global configurations, which enables your entire application to access these configurations everywhere.
i18n Configurations
Configure i18n related properties via Config Provider, to get language switching feature.
Use two attributes to provide i18n related config
The button switches the language of what is inside the provider: its
locale follows a store, as upstream’s
computed(() => zhCn or en) – Element’s locale objects,
whose files come with the provider. The page’s own language is
el_page(locale =); from the server,
update_el_config_provider(locale =).
vue_store("cfg_lang", state = list(language = "zh-cn"))
el_button(
"toggle",
"Switch Language",
on = list(
click = "$vueStore.cfg_lang.language = $vueStore.cfg_lang.language === 'zh-cn' ? 'en' : 'zh-cn'"
)
)
tags$br()
el_config_provider(
id = "cfg",
locale = v_bind(
"$vueStore.cfg_lang.language === 'zh-cn' ? ElementPlusLocaleZhCn : ElementPlusLocaleEn"
),
el_table(data = data.frame(date = character(), name = character())),
el_pagination("cfg_pg", total = 100, layout = "total, prev, pager, next")
)Button Configurations
The checkboxes and the select are a store’s fields, [v_model()]; the
provider’s button settings the store’s state, [v_bind()] –
the reactive object upstream gives, which the button inside takes as its
defaults – all in the browser.
vue_store(
"cfg_button",
state = list(
autoInsertSpace = TRUE,
type = "default",
plain = TRUE,
round = TRUE,
text = FALSE,
dashed = FALSE
)
)
tags$div(
el_checkbox(
"cfg_space",
"autoInsertSpace",
value = v_model("$vueStore.cfg_button.autoInsertSpace")
),
el_checkbox(
"cfg_plain",
"plain",
value = v_model("$vueStore.cfg_button.plain")
),
el_checkbox(
"cfg_round",
"round",
value = v_model("$vueStore.cfg_button.round")
),
el_checkbox(
"cfg_dashed",
"dashed",
value = v_model("$vueStore.cfg_button.dashed")
),
el_checkbox("cfg_text", "text", value = v_model("$vueStore.cfg_button.text")),
el_select(
"cfg_type",
choices = c("primary", "success", "warning", "danger", "info", "default"),
selected = v_model("$vueStore.cfg_button.type"),
width = "150px"
)
)
el_divider()
el_config_provider(
id = "cfg",
button = v_bind("$vueStore.cfg_button.$state"),
el_button("cfg_btn", "中文")
)Link Configurations
The selects set the provider’s link settings, a store’s
state, which the link inside takes as its defaults.
vue_store(
"cfg_links",
state = list(type = "success", underline = "always")
)
tags$div(
style = "display: flex; gap: 16px",
tags$div(
style = "display: flex; flex-direction: column; gap: 4px; flex-basis: 150px",
tags$span("Type:"),
el_select(
"cfg_type",
choices = c("primary", "success", "warning", "info", "danger", "default"),
selected = v_model("$vueStore.cfg_links.type")
)
),
tags$div(
style = "display: flex; flex-direction: column; gap: 4px; flex-basis: 150px",
tags$span("Underline:"),
el_select(
"cfg_underline",
choices = c("always", "never", "hover"),
selected = v_model("$vueStore.cfg_links.underline")
)
)
)
el_divider()
el_config_provider(
id = "cfg",
link = v_bind("$vueStore.cfg_links.$state"),
el_link("Link desu!", id = "cfg_link")
)Card Configurations
The radios set the provider’s card settings through a
store’s getter; a card inside takes them when it sets no
shadow of its own.
vue_store(
"cfg_card",
state = list(shadow = "always"),
getters = list(config = JS("function(s) { return { shadow: s.shadow }; }"))
)
tags$span("Shadow:")
el_radio_group(
"cfg_shadow",
choices = c("always", "hover", "never"),
value = v_model("$vueStore.cfg_card.shadow")
)
el_divider()
el_config_provider(
id = "cfg",
card = v_bind("$vueStore.cfg_card.config"),
el_card("Card desu!")
)Dialog Configurations
The switches set the provider’s dialog settings through
a store’s getter, which the dialog inside takes as its defaults;
overflow is off while the dialog cannot be dragged.
Element’s transition setting is not taken: the dialog is
markup and plays Element’s own dialog-fade.
vue_store(
"cfg_dialog",
state = list(
alignCenter = FALSE,
draggable = FALSE,
overflow = FALSE,
open = FALSE
),
getters = list(
config = JS(
"function(s) { return { alignCenter: s.alignCenter, draggable: s.draggable, overflow: s.overflow }; }"
),
fixed = JS("function(s) { return !s.draggable; }")
)
)
tags$div(
style = "display: flex; flex-direction: column; gap: 16px",
el_switch(
"cfg_align",
value = v_model("$vueStore.cfg_dialog.alignCenter"),
active_text = "alignCenter"
),
tags$div(
style = "display: flex; gap: 16px",
el_switch(
"cfg_drag",
value = v_model("$vueStore.cfg_dialog.draggable"),
active_text = "draggable"
),
el_switch(
"cfg_overflow",
value = v_model("$vueStore.cfg_dialog.overflow"),
active_text = "overflow",
disabled = v_bind("$vueStore.cfg_dialog.fixed")
)
),
tags$div(
el_button(
"cfg_open",
"Open Dialog",
type = "primary",
size = "small",
on = list(click = "$vueStore.cfg_dialog.open = true")
)
)
)
el_config_provider(
id = "cfg",
dialog = v_bind("$vueStore.cfg_dialog.config"),
el_dialog(
"cfg_dlg",
title = "Dialog Title",
destroy_on_close = TRUE,
visible = v_model("$vueStore.cfg_dialog.open"),
content = "Dialog Content"
)
)Message Configurations
The provider’s message settings are Element Plus’s
page-wide message defaults, so they reach every message on the page –
$message() in the browser, el_message() from
the server: at most three at a time, plain, at the bottom.
el_config_provider(
message = list(max = 3, plain = TRUE, placement = "bottom"),
el_button(
"cfg_msg",
"OPEN",
on = list(click = "$message('This is a message from bottom.')")
)
)Empty Values Configurations
Supported components list
- Cascader
- ColorPicker 2.10.3
- DatePicker
- Select
- SelectV2
- TimePicker
- TimeSelect
- TreeSelect
Set empty-values to support empty values of components.
The fallback value is ['', null, undefined]. If you think
the empty string is meaningful, write
[undefined, null].
Set value-on-clear to set the return value when cleared.
The fallback value is undefined. In the date component is
null. If you want to set undefined, use
() => undefined.
el_config_provider(
value_on_clear = NULL,
empty_values = list(NULL),
el_select(
"cfg_sel",
choices = c("Option1", "Option2", "Option3"),
clearable = TRUE,
placeholder = "Select",
width = "240px"
)
)Table Configurations
The checkbox and the select set the provider’s table
settings, a store’s state: a column that sets no
show_overflow_tooltip of its own takes them.
vue_store(
"cfg_table",
state = list(showOverflowTooltip = TRUE, tooltipEffect = "dark")
)
tags$div(
el_checkbox(
"cfg_tip",
"showOverflowTooltip",
value = v_model("$vueStore.cfg_table.showOverflowTooltip")
),
el_select(
"cfg_effect",
choices = c(dark = "dark", light = "light"),
selected = v_model("$vueStore.cfg_table.tooltipEffect"),
width = "150px"
)
)
el_divider()
el_config_provider(
id = "cfg",
table = v_bind("$vueStore.cfg_table.$state"),
el_table(
data = data.frame(
date = c("2016-05-03", "2016-05-02", "2016-05-04"),
name = "Tom",
address = "No. 189, Grove St, Los Angeles, a long address for the cell"
),
selection = TRUE,
columns = list(
el_table_column("date", "Date", width = 120),
el_table_column("name", "Name", width = 120),
el_table_column(
"address",
"Address (inherited from config-provider)",
width = 300
),
el_table_column(
"address",
"Address (explicit false)",
show_overflow_tooltip = FALSE
)
)
)
)Experimental features
In this section, you can learn how to use Config Provider to provide experimental features. For now, we haven’t added any experimental features, but in the feature roadmap, we will add some experimental features. You can use this config to manage the features you want or not.
API
Element Plus’s tables, and beside each entry where it is in R.
Config Provider Attributes
| Element | In R | Description | Type | Accepted | Default |
|---|---|---|---|---|---|
locale |
el_page(locale =) |
Locale Object |
1{name: string, el: TranslatePair}
languages
|
en | |
size |
size |
global component size |
2'large' \\| 'default' \\| 'small'
|
default | |
zIndex |
el_page(z_index =) |
global Initial zIndex | 3 | — | |
namespace |
(fixed:el)
|
global component className prefix (cooperated with $namespace) | 4 | el | |
button |
button |
button related configuration, see the following table |
5{autoInsertSpace?: boolean, type?: string, plain?: boolean, text?: boolean, round?: boolean, dashed?: boolean}
|
see the following table | |
link |
link |
link related configuration, see the following table |
6{type?: string, underline?: boolean \\| string}
|
see the following table | |
dialog |
dialog |
dialog related configuration, see the following table |
7{alignCenter?: boolean, draggable?: boolean, overflow?: boolean, transition?: DialogTransition}
|
see the following table | |
message |
message |
message related configuration, see the following table |
8{max?: number}
|
see the following table | |
experimental-features |
experimental_features |
features at experimental stage to be added, all features are default to be set to false | 9 | — | |
empty-values |
empty_values |
global empty values of components | 10 | — | |
value-on-clear |
value_on_clear |
global clear return value | 11 / 12 / 13 / 14 | — | |
table |
table |
table related configuration, see the following table |
15{showOverflowTooltip?: boolean \\| object, tooltipEffect?: string, tooltipOptions?: object, tooltipFormatter?: Function}
|
see the following table |