Skip to content
GitLab
Explore
Projects
Groups
Snippets
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Bootstrap
bootstrap
Commits
04ab8ba4
Commit
04ab8ba4
authored
3 years ago
by
GeoSot
Browse files
Options
Download
Email Patches
Plain Diff
feat(config.js): provide a `setConfig` method for all js components
parent
d388bd6e
gs/provide-steConfig-method
1 merge request
!36332
Provide a `setConfig` method for all js components
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
js/src/base-component.js
+2
-2
js/src/base-component.js
js/src/dropdown.js
+2
-2
js/src/dropdown.js
js/src/tooltip.js
+1
-1
js/src/tooltip.js
js/src/util/backdrop.js
+1
-1
js/src/util/backdrop.js
js/src/util/config.js
+11
-2
js/src/util/config.js
js/src/util/focustrap.js
+1
-1
js/src/util/focustrap.js
js/src/util/swipe.js
+1
-1
js/src/util/swipe.js
js/src/util/template-factory.js
+1
-1
js/src/util/template-factory.js
js/tests/unit/util/config.spec.js
+43
-0
js/tests/unit/util/config.spec.js
with
63 additions
and
11 deletions
+63
-11
js/src/base-component.js
+
2
-
2
View file @
04ab8ba4
...
...
@@ -30,7 +30,7 @@ class BaseComponent extends Config {
}
this
.
_element
=
element
this
.
_c
onfig
=
this
.
_getConfig
(
config
)
this
.
setC
onfig
(
this
.
_get
Initial
Config
(
config
)
)
Data
.
set
(
this
.
_element
,
this
.
constructor
.
DATA_KEY
,
this
)
}
...
...
@@ -49,7 +49,7 @@ class BaseComponent extends Config {
executeAfterTransition
(
callback
,
element
,
isAnimated
)
}
_getConfig
(
config
)
{
_get
Initial
Config
(
config
)
{
config
=
this
.
_mergeConfigObj
(
config
,
this
.
_element
)
config
=
this
.
_configAfterMerge
(
config
)
this
.
_typeCheckConfig
(
config
)
...
...
This diff is collapsed.
Click to expand it.
js/src/dropdown.js
+
2
-
2
View file @
04ab8ba4
...
...
@@ -205,8 +205,8 @@ class Dropdown extends BaseComponent {
EventHandler
.
trigger
(
this
.
_element
,
EVENT_HIDDEN
,
relatedTarget
)
}
_getConfig
(
config
)
{
config
=
super
.
_getConfig
(
config
)
_get
Initial
Config
(
config
)
{
config
=
super
.
_get
Initial
Config
(
config
)
if
(
typeof
config
.
reference
===
'
object
'
&&
!
isElement
(
config
.
reference
)
&&
typeof
config
.
reference
.
getBoundingClientRect
!==
'
function
'
...
...
This diff is collapsed.
Click to expand it.
js/src/tooltip.js
+
1
-
1
View file @
04ab8ba4
...
...
@@ -562,7 +562,7 @@ class Tooltip extends BaseComponent {
return
Object
.
values
(
this
.
_activeTrigger
).
includes
(
true
)
}
_getConfig
(
config
)
{
_get
Initial
Config
(
config
)
{
const
dataAttributes
=
Manipulator
.
getDataAttributes
(
this
.
_element
)
for
(
const
dataAttribute
of
Object
.
keys
(
dataAttributes
))
{
...
...
This diff is collapsed.
Click to expand it.
js/src/util/backdrop.js
+
1
-
1
View file @
04ab8ba4
...
...
@@ -41,7 +41,7 @@ const DefaultType = {
class
Backdrop
extends
Config
{
constructor
(
config
)
{
super
()
this
.
_c
onfig
=
this
.
_getConfig
(
config
)
this
.
setC
onfig
(
this
.
_get
Initial
Config
(
config
)
)
this
.
_isAppended
=
false
this
.
_element
=
null
}
...
...
This diff is collapsed.
Click to expand it.
js/src/util/config.js
+
11
-
2
View file @
04ab8ba4
...
...
@@ -13,6 +13,8 @@ import Manipulator from '../dom/manipulator'
*/
class
Config
{
_config
=
{}
// Getters
static
get
Default
()
{
return
{}
...
...
@@ -26,10 +28,17 @@ class Config {
throw
new
Error
(
'
You have to implement the static method "NAME", for each component!
'
)
}
_getConfig
(
config
)
{
setConfig
(
config
)
{
this
.
_typeCheckConfig
(
config
)
this
.
_config
=
{
...
this
.
_config
,
...(
typeof
config
===
'
object
'
?
config
:
{})
}
}
_getInitialConfig
(
config
)
{
config
=
this
.
_mergeConfigObj
(
config
)
config
=
this
.
_configAfterMerge
(
config
)
this
.
_typeCheckConfig
(
config
)
return
config
}
...
...
This diff is collapsed.
Click to expand it.
js/src/util/focustrap.js
+
1
-
1
View file @
04ab8ba4
...
...
@@ -40,7 +40,7 @@ const DefaultType = {
class
FocusTrap
extends
Config
{
constructor
(
config
)
{
super
()
this
.
_c
onfig
=
this
.
_getConfig
(
config
)
this
.
setC
onfig
(
this
.
_get
Initial
Config
(
config
)
)
this
.
_isActive
=
false
this
.
_lastTabNavDirection
=
null
}
...
...
This diff is collapsed.
Click to expand it.
js/src/util/swipe.js
+
1
-
1
View file @
04ab8ba4
...
...
@@ -50,7 +50,7 @@ class Swipe extends Config {
return
}
this
.
_c
onfig
=
this
.
_getConfig
(
config
)
this
.
setC
onfig
(
this
.
_get
Initial
Config
(
config
)
)
this
.
_deltaX
=
0
this
.
_supportPointerEvents
=
Boolean
(
window
.
PointerEvent
)
this
.
_initEvents
()
...
...
This diff is collapsed.
Click to expand it.
js/src/util/template-factory.js
+
1
-
1
View file @
04ab8ba4
...
...
@@ -48,7 +48,7 @@ const DefaultContentType = {
class
TemplateFactory
extends
Config
{
constructor
(
config
)
{
super
()
this
.
_c
onfig
=
this
.
_getConfig
(
config
)
this
.
setC
onfig
(
this
.
_get
Initial
Config
(
config
)
)
}
// Getters
...
...
This diff is collapsed.
Click to expand it.
js/tests/unit/util/config.spec.js
+
43
-
0
View file @
04ab8ba4
...
...
@@ -37,6 +37,49 @@ describe('Config', () => {
})
})
describe
(
'
setConfig
'
,
()
=>
{
it
(
'
should merge config object
'
,
()
=>
{
const
instance
=
new
DummyConfigClass
()
spyOnProperty
(
DummyConfigClass
,
'
DefaultType
'
,
'
get
'
).
and
.
returnValue
({
testBool
:
'
boolean
'
,
testString
:
'
string
'
})
instance
.
setConfig
({
testBool
:
true
,
testString
:
'
foo
'
})
expect
(
instance
.
_config
.
testBool
).
toBeTrue
()
expect
(
instance
.
_config
.
testString
).
toEqual
(
'
foo
'
)
instance
.
setConfig
({
testBool
:
false
,
testString
:
'
bar
'
})
expect
(
instance
.
_config
.
testBool
).
toBeFalse
()
expect
(
instance
.
_config
.
testString
).
toEqual
(
'
bar
'
)
})
it
(
'
should check values before merging them
'
,
()
=>
{
const
instance
=
new
DummyConfigClass
()
spyOnProperty
(
DummyConfigClass
,
'
DefaultType
'
,
'
get
'
).
and
.
returnValue
({
testBool
:
'
boolean
'
,
testString
:
'
string
'
})
expect
(()
=>
{
instance
.
setConfig
({
testBool
:
'
foo
'
,
testString
:
true
})
}).
toThrowError
(
TypeError
)
})
})
describe
(
'
mergeConfigObj
'
,
()
=>
{
it
(
'
should parse element
\'
s data attributes and merge it with default config. Element
\'
s data attributes must excel Defaults
'
,
()
=>
{
fixtureEl
.
innerHTML
=
'
<div id="test" data-bs-test-bool="false" data-bs-test-int="8" data-bs-test-string1="bar"></div>
'
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Explore
Projects
Groups
Snippets