@rhavenside/baseline 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (80) hide show
  1. package/README.md +472 -0
  2. package/dist/base-line.css +5 -0
  3. package/dist/base-line.css.map +1 -0
  4. package/dist/fonts/GoogleSansCode-Bold.ttf +0 -0
  5. package/dist/fonts/GoogleSansCode-BoldItalic.ttf +0 -0
  6. package/dist/fonts/GoogleSansCode-ExtraBold.ttf +0 -0
  7. package/dist/fonts/GoogleSansCode-ExtraBoldItalic.ttf +0 -0
  8. package/dist/fonts/GoogleSansCode-Italic-VariableFont_wght.ttf +0 -0
  9. package/dist/fonts/GoogleSansCode-Italic.ttf +0 -0
  10. package/dist/fonts/GoogleSansCode-Light.ttf +0 -0
  11. package/dist/fonts/GoogleSansCode-LightItalic.ttf +0 -0
  12. package/dist/fonts/GoogleSansCode-Medium.ttf +0 -0
  13. package/dist/fonts/GoogleSansCode-MediumItalic.ttf +0 -0
  14. package/dist/fonts/GoogleSansCode-Regular.ttf +0 -0
  15. package/dist/fonts/GoogleSansCode-SemiBold.ttf +0 -0
  16. package/dist/fonts/GoogleSansCode-SemiBoldItalic.ttf +0 -0
  17. package/dist/fonts/GoogleSansCode-VariableFont_wght.ttf +0 -0
  18. package/dist/fonts/RobotoCondensed-Black.ttf +0 -0
  19. package/dist/fonts/RobotoCondensed-BlackItalic.ttf +0 -0
  20. package/dist/fonts/RobotoCondensed-Bold.ttf +0 -0
  21. package/dist/fonts/RobotoCondensed-BoldItalic.ttf +0 -0
  22. package/dist/fonts/RobotoCondensed-ExtraBold.ttf +0 -0
  23. package/dist/fonts/RobotoCondensed-ExtraBoldItalic.ttf +0 -0
  24. package/dist/fonts/RobotoCondensed-ExtraLight.ttf +0 -0
  25. package/dist/fonts/RobotoCondensed-ExtraLightItalic.ttf +0 -0
  26. package/dist/fonts/RobotoCondensed-Italic-VariableFont_wght.ttf +0 -0
  27. package/dist/fonts/RobotoCondensed-Italic.ttf +0 -0
  28. package/dist/fonts/RobotoCondensed-Light.ttf +0 -0
  29. package/dist/fonts/RobotoCondensed-LightItalic.ttf +0 -0
  30. package/dist/fonts/RobotoCondensed-Medium.ttf +0 -0
  31. package/dist/fonts/RobotoCondensed-MediumItalic.ttf +0 -0
  32. package/dist/fonts/RobotoCondensed-Regular.ttf +0 -0
  33. package/dist/fonts/RobotoCondensed-SemiBold.ttf +0 -0
  34. package/dist/fonts/RobotoCondensed-SemiBoldItalic.ttf +0 -0
  35. package/dist/fonts/RobotoCondensed-Thin.ttf +0 -0
  36. package/dist/fonts/RobotoCondensed-ThinItalic.ttf +0 -0
  37. package/dist/fonts/RobotoCondensed-VariableFont_wght.ttf +0 -0
  38. package/dist/fonts/ZalandoSansExpanded-Black.ttf +0 -0
  39. package/dist/fonts/ZalandoSansExpanded-BlackItalic.ttf +0 -0
  40. package/dist/fonts/ZalandoSansExpanded-Bold.ttf +0 -0
  41. package/dist/fonts/ZalandoSansExpanded-BoldItalic.ttf +0 -0
  42. package/dist/fonts/ZalandoSansExpanded-ExtraBold.ttf +0 -0
  43. package/dist/fonts/ZalandoSansExpanded-ExtraBoldItalic.ttf +0 -0
  44. package/dist/fonts/ZalandoSansExpanded-ExtraLight.ttf +0 -0
  45. package/dist/fonts/ZalandoSansExpanded-ExtraLightItalic.ttf +0 -0
  46. package/dist/fonts/ZalandoSansExpanded-Italic-VariableFont_wght.ttf +0 -0
  47. package/dist/fonts/ZalandoSansExpanded-Italic.ttf +0 -0
  48. package/dist/fonts/ZalandoSansExpanded-Light.ttf +0 -0
  49. package/dist/fonts/ZalandoSansExpanded-LightItalic.ttf +0 -0
  50. package/dist/fonts/ZalandoSansExpanded-Medium.ttf +0 -0
  51. package/dist/fonts/ZalandoSansExpanded-MediumItalic.ttf +0 -0
  52. package/dist/fonts/ZalandoSansExpanded-Regular.ttf +0 -0
  53. package/dist/fonts/ZalandoSansExpanded-SemiBold.ttf +0 -0
  54. package/dist/fonts/ZalandoSansExpanded-SemiBoldItalic.ttf +0 -0
  55. package/dist/fonts/ZalandoSansExpanded-VariableFont_wght.ttf +0 -0
  56. package/dist/fonts/baseline-icons.woff +0 -0
  57. package/dist/fonts/baseline-icons.woff2 +0 -0
  58. package/dist/js/accordion.js +103 -0
  59. package/dist/js/alert.js +91 -0
  60. package/dist/js/base.js +146 -0
  61. package/dist/js/button.js +80 -0
  62. package/dist/js/carousel.js +427 -0
  63. package/dist/js/collapse.js +233 -0
  64. package/dist/js/color-modes.js +70 -0
  65. package/dist/js/component.js +114 -0
  66. package/dist/js/dropdown.js +348 -0
  67. package/dist/js/index.js +108 -0
  68. package/dist/js/modal.js +440 -0
  69. package/dist/js/offcanvas.js +356 -0
  70. package/dist/js/popover.js +241 -0
  71. package/dist/js/swipe.js +143 -0
  72. package/dist/js/tab.js +285 -0
  73. package/dist/js/toast.js +228 -0
  74. package/dist/js/tooltip.js +716 -0
  75. package/dist/js/util/backdrop.js +133 -0
  76. package/dist/js/util/component-functions.js +111 -0
  77. package/dist/js/util/focustrap.js +101 -0
  78. package/dist/js/util/scrollbar.js +111 -0
  79. package/dist/js/util.js +564 -0
  80. package/package.json +47 -0
Binary file
Binary file
@@ -0,0 +1,103 @@
1
+ /**
2
+ * Base-Line Accordion Component
3
+ * Baseline 2.0 compatible accordion with Base-Line naming
4
+ */
5
+
6
+ import Collapse from './collapse.js'
7
+ import { getElement, getElements, on } from './util.js'
8
+ import { addClass, removeClass, hasClass } from './component.js'
9
+
10
+ const NAME = 'accordion'
11
+ const DATA_KEY = `c.${NAME}`
12
+ const EVENT_KEY = `.${DATA_KEY}`
13
+ const DATA_API_KEY = `[data-c-${NAME}]`
14
+
15
+ const EVENT_CLICK_DATA_API = `click${EVENT_KEY}${DATA_API_KEY}`
16
+
17
+ const CLASS_NAME_COLLAPSED = 'c-collapsed'
18
+ const SELECTOR_ACCORDION = '.c-accordion'
19
+ const SELECTOR_ACCORDION_ITEM = '.c-accordion-item'
20
+ const SELECTOR_ACCORDION_BUTTON = '.c-accordion-button'
21
+
22
+ class Accordion {
23
+ constructor(element) {
24
+ this._element = element
25
+ this._items = getElements(SELECTOR_ACCORDION_ITEM, this._element)
26
+ this._init()
27
+ }
28
+
29
+ _init() {
30
+ this._items.forEach((item, index) => {
31
+ const button = getElement(SELECTOR_ACCORDION_BUTTON, item)
32
+ const collapse = getElement('.c-collapse', item)
33
+
34
+ if (button && collapse) {
35
+ on(button, 'click', (e) => {
36
+ e.preventDefault()
37
+ this._toggleItem(item, index)
38
+ })
39
+ }
40
+ })
41
+ }
42
+
43
+ _toggleItem(item, index) {
44
+ const button = getElement(SELECTOR_ACCORDION_BUTTON, item)
45
+ const collapse = getElement('.c-collapse', item)
46
+
47
+ if (!button || !collapse) {
48
+ return
49
+ }
50
+
51
+ const isExpanded = hasClass(button, CLASS_NAME_COLLAPSED) === false
52
+
53
+ // Close all other items
54
+ this._items.forEach((otherItem, otherIndex) => {
55
+ if (otherIndex !== index) {
56
+ const otherButton = getElement(SELECTOR_ACCORDION_BUTTON, otherItem)
57
+ const otherCollapse = getElement('.c-collapse', otherItem)
58
+
59
+ if (otherButton && otherCollapse && !hasClass(otherButton, CLASS_NAME_COLLAPSED)) {
60
+ const collapseInstance = Collapse.getOrCreateInstance(otherCollapse)
61
+ collapseInstance.hide()
62
+ addClass(otherButton, CLASS_NAME_COLLAPSED)
63
+ }
64
+ }
65
+ })
66
+
67
+ // Toggle current item
68
+ const collapseInstance = Collapse.getOrCreateInstance(collapse)
69
+
70
+ if (isExpanded) {
71
+ collapseInstance.hide()
72
+ addClass(button, CLASS_NAME_COLLAPSED)
73
+ } else {
74
+ collapseInstance.show()
75
+ removeClass(button, CLASS_NAME_COLLAPSED)
76
+ }
77
+ }
78
+
79
+ static getOrCreateInstance(element) {
80
+ return element._baseLineAccordion || new Accordion(element)
81
+ }
82
+ }
83
+
84
+ // Data API - Accordions are auto-initialized, no need for click handler
85
+
86
+ // Auto-initialize accordions
87
+ if (typeof document !== 'undefined') {
88
+ const initAccordions = () => {
89
+ const accordions = document.querySelectorAll(SELECTOR_ACCORDION)
90
+ accordions.forEach(accordion => {
91
+ Accordion.getOrCreateInstance(accordion)
92
+ })
93
+ }
94
+
95
+ if (document.readyState === 'loading') {
96
+ document.addEventListener('DOMContentLoaded', initAccordions)
97
+ } else {
98
+ initAccordions()
99
+ }
100
+ }
101
+
102
+ export default Accordion
103
+
@@ -0,0 +1,91 @@
1
+ /**
2
+ * Base-Line Alert Component
3
+ * Baseline 2.0 compatible alert with Base-Line naming
4
+ */
5
+
6
+ import { BaseComponent } from './base.js'
7
+ import { getElement, getElements, on, executeAfterTransition } from './util.js'
8
+ import { removeClass } from './component.js'
9
+
10
+ const NAME = 'alert'
11
+ const DATA_KEY = `c.${NAME}`
12
+ const EVENT_KEY = `.${DATA_KEY}`
13
+ const DATA_API_KEY = `[data-c-${NAME}]`
14
+
15
+ const EVENT_CLOSE = `close${EVENT_KEY}`
16
+ const EVENT_CLOSED = `closed${EVENT_KEY}`
17
+ const EVENT_CLICK_DATA_API = `click${EVENT_KEY}${DATA_API_KEY}`
18
+
19
+ const CLASS_NAME_FADE = 'c-fade'
20
+ const CLASS_NAME_SHOW = 'is-show'
21
+ const SELECTOR_DATA_DISMISS = '[data-c-dismiss="alert"]'
22
+
23
+ class Alert extends BaseComponent {
24
+ constructor(element) {
25
+ super(element)
26
+ this._init()
27
+ }
28
+
29
+ static get NAME() {
30
+ return NAME
31
+ }
32
+
33
+ _init() {
34
+ this._bindEvents()
35
+ }
36
+
37
+ _bindEvents() {
38
+ const dismissButtons = getElements(SELECTOR_DATA_DISMISS, this._element)
39
+ dismissButtons.forEach(button => {
40
+ on(button, 'click', () => this.close())
41
+ })
42
+ }
43
+
44
+ close() {
45
+ const closeEvent = new CustomEvent(EVENT_CLOSE, {
46
+ bubbles: true,
47
+ cancelable: true
48
+ })
49
+
50
+ this._element.dispatchEvent(closeEvent)
51
+
52
+ if (closeEvent.defaultPrevented) {
53
+ return
54
+ }
55
+
56
+ this._element.classList.remove(CLASS_NAME_SHOW)
57
+
58
+ const isAnimated = this._element.classList.contains(CLASS_NAME_FADE)
59
+
60
+ if (isAnimated) {
61
+ executeAfterTransition(() => {
62
+ this._element.remove()
63
+ const closedEvent = new CustomEvent(EVENT_CLOSED, { bubbles: true })
64
+ this._element.dispatchEvent(closedEvent)
65
+ }, this._element)
66
+ } else {
67
+ this._element.remove()
68
+ const closedEvent = new CustomEvent(EVENT_CLOSED, { bubbles: true })
69
+ this._element.dispatchEvent(closedEvent)
70
+ }
71
+ }
72
+
73
+ static getOrCreateInstance(element) {
74
+ return element._baseLineComponent || new Alert(element)
75
+ }
76
+ }
77
+
78
+ // Data API
79
+ on(document, 'click', SELECTOR_DATA_DISMISS, function (event) {
80
+ event.preventDefault()
81
+ const alert = this.closest('.c-alert')
82
+ if (alert) {
83
+ const alertInstance = Alert.getOrCreateInstance(alert)
84
+ alertInstance.close()
85
+ }
86
+ })
87
+
88
+ export default Alert
89
+
90
+
91
+
@@ -0,0 +1,146 @@
1
+ /**
2
+ * Base-Line JavaScript Base
3
+ * Data API and component initialization
4
+ */
5
+
6
+ import { onDOMContentLoaded, getjQuery, executeAfterTransition, getDataAttributes } from './util.js'
7
+
8
+ /**
9
+ * Data API - Initialize components via data attributes
10
+ */
11
+ class DataAPI {
12
+ constructor() {
13
+ this.components = new Map()
14
+ }
15
+
16
+ /**
17
+ * Register a component
18
+ */
19
+ register(name, ComponentClass) {
20
+ this.components.set(name, ComponentClass)
21
+ }
22
+
23
+ /**
24
+ * Initialize components from data attributes
25
+ */
26
+ init() {
27
+ this.components.forEach((ComponentClass, name) => {
28
+ const selector = `[data-c-${name}]`
29
+ const elements = document.querySelectorAll(selector)
30
+
31
+ elements.forEach(element => {
32
+ if (!element._baseLineComponent) {
33
+ const instance = new ComponentClass(element)
34
+ element._baseLineComponent = instance
35
+ }
36
+ })
37
+ })
38
+ }
39
+
40
+ /**
41
+ * Get component instance from element
42
+ */
43
+ getInstance(element, componentName) {
44
+ if (element._baseLineComponent) {
45
+ return element._baseLineComponent
46
+ }
47
+
48
+ const ComponentClass = this.components.get(componentName)
49
+ if (ComponentClass) {
50
+ const instance = new ComponentClass(element)
51
+ element._baseLineComponent = instance
52
+ return instance
53
+ }
54
+
55
+ return null
56
+ }
57
+ }
58
+
59
+ // Global Data API instance
60
+ export const dataAPI = new DataAPI()
61
+
62
+ /**
63
+ * Base Component Class
64
+ */
65
+ export class BaseComponent {
66
+ constructor(element, config = {}) {
67
+ this._element = element
68
+
69
+ // Merge config in order: Defaults → data-Attribute → config → _configAfterMerge
70
+ // This matches Baseline-main's behavior where data attributes are automatically read
71
+ const dataAttributes = getDataAttributes(element)
72
+ const mergedConfig = {
73
+ ...this.constructor.Default,
74
+ ...dataAttributes,
75
+ ...config
76
+ }
77
+ this._config = this._configAfterMerge ? this._configAfterMerge(mergedConfig) : mergedConfig
78
+ }
79
+
80
+ static get NAME() {
81
+ throw new Error('You have to implement the static getter NAME')
82
+ }
83
+
84
+ static get Default() {
85
+ return {}
86
+ }
87
+
88
+ dispose() {
89
+ if (this._element) {
90
+ this._element._baseLineComponent = null
91
+ this._element = null
92
+ }
93
+ }
94
+
95
+ /**
96
+ * Queue callback for after transition
97
+ */
98
+ _queueCallback(callback, element, isAnimated = true) {
99
+ if (!isAnimated) {
100
+ callback()
101
+ return
102
+ }
103
+
104
+ executeAfterTransition(callback, element)
105
+ }
106
+
107
+ /**
108
+ * jQuery interface
109
+ */
110
+ static jQueryInterface(config) {
111
+ return this.each(function () {
112
+ const $element = getjQuery()(this)
113
+ let data = $element.data('c-' + this.constructor.NAME.toLowerCase())
114
+ const _config = typeof config === 'object' && config ? config : {}
115
+
116
+ if (!data) {
117
+ data = new this.constructor(this, _config)
118
+ $element.data('c-' + this.constructor.NAME.toLowerCase(), data)
119
+ }
120
+
121
+ if (typeof config === 'string') {
122
+ if (typeof data[config] === 'undefined') {
123
+ throw new TypeError(`No method named "${config}"`)
124
+ }
125
+ data[config](this)
126
+ }
127
+ })
128
+ }
129
+ }
130
+
131
+ /**
132
+ * Initialize all components on DOM ready
133
+ */
134
+ onDOMContentLoaded(() => {
135
+ dataAPI.init()
136
+ })
137
+
138
+ // Export for global access
139
+ if (typeof window !== 'undefined') {
140
+ window.BaseLine = window.BaseLine || {}
141
+ window.BaseLine.dataAPI = dataAPI
142
+ window.BaseLine.BaseComponent = BaseComponent
143
+ }
144
+
145
+
146
+
@@ -0,0 +1,80 @@
1
+ /**
2
+ * Base-Line Button Component
3
+ * Baseline 2.0 compatible button with Base-Line naming
4
+ */
5
+
6
+ import { BaseComponent } from './base.js'
7
+ import { getElement, getElements, on } from './util.js'
8
+
9
+ const NAME = 'button'
10
+ const DATA_KEY = `c.${NAME}`
11
+ const EVENT_KEY = `.${DATA_KEY}`
12
+ const DATA_API_KEY = `[data-c-${NAME}]`
13
+
14
+ const CLASS_NAME_ACTIVE = 'is-active'
15
+ const CLASS_NAME_BUTTON = 'c-button'
16
+ const SELECTOR_DATA_TOGGLE = '[data-c-toggle="button"]'
17
+ const SELECTOR_INPUT = 'input:not([type="hidden"])'
18
+ const SELECTOR_ACTIVE = '.is-active'
19
+ const EVENT_CLICK_DATA_API = `click${EVENT_KEY}${DATA_API_KEY}`
20
+
21
+ class Button extends BaseComponent {
22
+ constructor(element) {
23
+ super(element)
24
+ this._init()
25
+ }
26
+
27
+ static get NAME() {
28
+ return NAME
29
+ }
30
+
31
+ _init() {
32
+ this._bindEvents()
33
+ }
34
+
35
+ _bindEvents() {
36
+ on(this._element, 'click', () => this.toggle())
37
+ }
38
+
39
+ toggle() {
40
+ if (this._element.hasAttribute('disabled') || this._element.classList.contains('is-disabled')) {
41
+ return
42
+ }
43
+
44
+ const isActive = this._element.classList.contains(CLASS_NAME_ACTIVE)
45
+
46
+ if (this._element.tagName === 'INPUT' || this._element.tagName === 'BUTTON') {
47
+ this._element.classList.toggle(CLASS_NAME_ACTIVE, !isActive)
48
+ }
49
+
50
+ if (this._element.tagName === 'INPUT' && this._element.type === 'checkbox') {
51
+ this._element.checked = !isActive
52
+ }
53
+
54
+ if (this._element.tagName === 'INPUT' && this._element.type === 'radio') {
55
+ const group = document.querySelectorAll(`input[name="${this._element.name}"]`)
56
+ group.forEach(input => {
57
+ input.classList.remove(CLASS_NAME_ACTIVE)
58
+ input.checked = false
59
+ })
60
+ this._element.classList.add(CLASS_NAME_ACTIVE)
61
+ this._element.checked = true
62
+ }
63
+ }
64
+
65
+ static getOrCreateInstance(element) {
66
+ return element._baseLineComponent || new Button(element)
67
+ }
68
+ }
69
+
70
+ // Data API
71
+ on(document, 'click', SELECTOR_DATA_TOGGLE, function (event) {
72
+ event.preventDefault()
73
+ const button = Button.getOrCreateInstance(this)
74
+ button.toggle()
75
+ })
76
+
77
+ export default Button
78
+
79
+
80
+