forked from liferay/clay
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(clayui.com): Move
code-collapse.js
code to CodeToggle
compone…
…nt? and update so it works in IE11 fix(clayui.com): CSS Pages should have code collapsed by default fix(clayui.com): Adds `focusable="false"` to code collapse svgs so IE11 doesn't focus them on tab
- Loading branch information
Showing
6 changed files
with
82 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/** | ||
* SPDX-FileCopyrightText: © 2018 Liferay, Inc. <https://liferay.com> | ||
* SPDX-License-Identifier: BSD-3-Clause | ||
*/ | ||
|
||
import React, {useEffect} from 'react'; | ||
|
||
const CodeToggle = (props) => { | ||
const handleCodeCollapse = (e) => { | ||
const isCodeCollapse = | ||
e.target.classList.contains('btn-collapse--collapse') || | ||
e.target.closest('.btn-collapse--collapse'); | ||
|
||
if (isCodeCollapse) { | ||
const codeContainer = e.target.closest('.code-container'); | ||
|
||
const isVisible = | ||
codeContainer.classList.contains('expanded'); | ||
|
||
const expanded = isVisible ? 'Expand' : 'Collapse'; | ||
|
||
codeContainer | ||
.querySelector('.btn-collapse--collapse') | ||
.setAttribute('title', expanded); | ||
|
||
codeContainer.classList.toggle('expanded'); | ||
} | ||
}; | ||
|
||
useEffect(() => { | ||
document.addEventListener('click', handleCodeCollapse, false); | ||
|
||
return () => { | ||
document.removeEventListener('click', handleCodeCollapse, false); | ||
}; | ||
}); | ||
|
||
return props.children; | ||
}; | ||
|
||
export default CodeToggle; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.