@daoyi/nmtl-ui 2.0.1-beta.13 → 2.0.1-beta.130
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.
- package/lib/components/Autocomplete-3b418e5f.js +494 -0
- package/lib/components/Autocomplete.js +20 -1
- package/lib/components/Avatar.js +59 -1
- package/lib/components/BackTop.js +124 -1
- package/lib/components/BarChart.js +764 -1
- package/lib/components/Breadcrumbs.js +122 -1
- package/lib/components/Button-7bd5aa09.js +114 -0
- package/lib/components/Button.js +7 -1
- package/lib/components/Carousel.js +4654 -1
- package/lib/components/Checkbox.js +37 -1
- package/lib/components/CollapseContent.js +180 -1
- package/lib/components/ContactModal-7e5b14e8.js +12188 -0
- package/lib/components/ContactModal.js +24 -3
- package/lib/components/Drawer-629e59c7.js +176 -0
- package/lib/components/Drawer.js +17 -1
- package/lib/components/Dropdown.js +134 -1
- package/lib/components/Empty-c6a44967.js +46 -0
- package/lib/components/Empty.js +5 -1
- package/lib/components/ExportButton.js +128 -1
- package/lib/components/ExtraTools-2691c13e.js +3676 -0
- package/lib/components/ExtraTools.js +11 -22
- package/lib/components/Filter.js +821 -12
- package/lib/components/Footer.js +317 -1
- package/lib/components/ForwardLink-5fbd2705.js +184 -0
- package/lib/components/ForwardLink.js +10 -0
- package/lib/components/Header.js +233 -1
- package/lib/components/Image.js +61 -1
- package/lib/components/Input.js +89 -1
- package/lib/components/InputMethod.js +33949 -12
- package/lib/components/KeywordSearch-fec33a2c.js +156 -0
- package/lib/components/KeywordSearch.js +22 -1
- package/lib/components/KeywordTicker.js +224 -1
- package/lib/components/Keywords.js +383 -1
- package/lib/components/Loading.js +32 -1
- package/lib/components/MUITheme.js +2657 -1
- package/lib/components/Modal-e04532fa.js +127 -0
- package/lib/components/Modal.js +11 -1
- package/lib/components/MoreButton-19055e07.js +148 -0
- package/lib/components/MoreButton.js +8 -1
- package/lib/components/Pagination.js +3702 -0
- package/lib/components/Radio.js +83 -1
- package/lib/components/SNA.js +1755 -22
- package/lib/components/Select-cb3e1ba1.js +189 -0
- package/lib/components/Select.js +14 -1
- package/lib/components/Spin-8f87eadc.js +79 -0
- package/lib/components/Spin.js +7 -1
- package/lib/components/Table.js +51 -1
- package/lib/components/Tooltip-6ebfa9c1.js +70 -0
- package/lib/components/Tooltip.js +7 -1
- package/lib/components/_commonjsHelpers-70de2c37.js +28 -0
- package/lib/components/_rollupPluginBabelHelpers-a52356f6.js +142 -0
- package/lib/components/createSvgIcon-e3803ee1.js +576 -0
- package/lib/components/dataExport-a9e3fae1.js +91 -0
- package/lib/components/debounce-127da66c.js +355 -0
- package/lib/components/defaultTheme-ed7746fe.js +1661 -0
- package/lib/components/globalConfig.js +423 -0
- package/lib/components/hoist-non-react-statics.cjs-3f408ad2.js +105 -0
- package/lib/components/index-b47819f3.js +481 -0
- package/lib/components/index-b76a85f4.js +61 -0
- package/lib/components/isObjectLike-e111475d.js +190 -0
- package/lib/components/style-inject.es-1f59c1d0.js +28 -1
- package/lib/components/toConsumableArray-dbe8af76.js +19 -0
- package/lib/components/transform-849a452c.js +5475 -0
- package/lib/components/useTheme-d16d02d9.js +11 -0
- package/lib/components/withTheme-2d778133.js +6 -0
- package/lib/configs/config.selector.js +151 -0
- package/lib/configs/index.d.ts +1 -0
- package/lib/configs/index.js +1 -0
- package/lib/index.d.ts +5 -1
- package/lib/index.js +5 -1
- package/lib/utils/_rollupPluginBabelHelpers-9802e640.js +121 -0
- package/lib/utils/arrayMerge.js +4953 -1
- package/lib/utils/chunkArray.js +15 -1
- package/lib/utils/convert2HtmlEntities.js +42 -1
- package/lib/utils/domToImage.js +802 -1
- package/lib/utils/downloadGephi.js +106 -1
- package/lib/utils/exportXlsx.js +221 -1
- package/lib/utils/historyAppendSearch.js +502 -1
- package/lib/utils/isDevelopMode.js +5 -1
- package/lib/utils/parseYMD.js +36 -1
- package/lib/utils/removeDuplicateItem.js +11 -1
- package/lib/utils/sendEmail.js +39 -1
- package/lib/utils/snaDefine-6a2bcd94.js +5 -0
- package/lib/utils/snaDefine.js +1 -1
- package/lib/utils/snaPreProcess.js +84 -1
- package/package.json +134 -128
- package/lib/components/Empty-54b79907.js +0 -1
- package/lib/components/KeywordSearch-5a393f12.js +0 -1
- package/lib/components/Select-f2441b83.js +0 -1
- package/lib/components/_rollupPluginBabelHelpers-1b8c042f.js +0 -1
- package/lib/components/_rollupPluginBabelHelpers-ec4e2a53.js +0 -1
- package/lib/components/createSvgIcon-62b64929.js +0 -1
- package/lib/components/createSvgIcon-e24792d4.js +0 -1
- package/lib/components/createTheme-7fffa109.js +0 -1
- package/lib/components/dataExport-9fccd4f0.js +0 -1
- package/lib/components/debounce-c993109b.js +0 -1
- package/lib/components/hoist-non-react-statics.cjs-d6a9befd.js +0 -1
- package/lib/components/index-11391ca3.js +0 -7
- package/lib/components/index-b2745105.js +0 -7
- package/lib/components/isObjectLike-2f1983fe.js +0 -1
- package/lib/components/style-inject.es-c875d022.js +0 -1
- package/lib/components/transform-95ae0119.js +0 -1
- package/lib/utils/_commonjsHelpers-e2cda605.js +0 -1
- package/lib/utils/_rollupPluginBabelHelpers-928a52ce.js +0 -1
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
import { c as _objectWithoutProperties } from './_rollupPluginBabelHelpers-a52356f6.js';
|
|
2
|
+
import React__default, { useMemo, useCallback } from 'react';
|
|
3
|
+
import PropTypes from 'prop-types';
|
|
4
|
+
import { c as classNames } from './index-b76a85f4.js';
|
|
5
|
+
import { q as queryString } from './index-b47819f3.js';
|
|
6
|
+
import { useHistory } from 'react-router-dom';
|
|
7
|
+
import { Tooltip } from '@material-ui/core';
|
|
8
|
+
import { getIntl } from './globalConfig';
|
|
9
|
+
import { s as styleInject } from './style-inject.es-1f59c1d0.js';
|
|
10
|
+
|
|
11
|
+
var css_248z = ".forwardLink {\n width: -moz-fit-content;\n width: fit-content;\n max-width: 100%;\n display: flex;\n}\n.forwardLink__link {\n color: unset;\n text-decoration: none;\n text-overflow: ellipsis;\n overflow: hidden;\n cursor: pointer;\n display: block;\n width: 100%;\n}\n.forwardLink__link--disabled {\n cursor: not-allowed;\n}";
|
|
12
|
+
styleInject(css_248z);
|
|
13
|
+
|
|
14
|
+
var _excluded = ["className", "linkClassName", "title", "target", "disabled", "children", "tip", "onClick"];
|
|
15
|
+
|
|
16
|
+
/*
|
|
17
|
+
* 導頁前綴沿用目前網址的語系段(/en/…、/zh-tw/…)。
|
|
18
|
+
* 原本寫死 '/zh-tw'(2023-03-18 暫時寫死),英文頁上的 ForwardLink 一律把使用者帶回中文站(nmtl-web i18n 盤點 D2)。
|
|
19
|
+
* history.location.pathname 不含 Router basename(各站 contextRoot),第一段就是語系;
|
|
20
|
+
* 只接受已知語系代碼,避免把 hr/lg/ra 這類兩個字母的子站代碼誤認成語系。
|
|
21
|
+
*/
|
|
22
|
+
var KNOWN_LOCALES = ['zh-tw', 'zh-cn', 'en', 'en-us'];
|
|
23
|
+
var DEFAULT_LOCALE = 'zh-tw';
|
|
24
|
+
var getLocalePrefix = function getLocalePrefix(pathname) {
|
|
25
|
+
var firstSegment = (pathname || '').split('/').filter(Boolean)[0];
|
|
26
|
+
return "/".concat(firstSegment && KNOWN_LOCALES.includes(firstSegment.toLowerCase()) ? firstSegment : DEFAULT_LOCALE);
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
/*
|
|
30
|
+
* ⚠️ 本元件刻意「不輸出 href 屬性」,請勿改回 <a> 或 react-router <Link>。
|
|
31
|
+
*
|
|
32
|
+
* 原因(2026-09-04 開發團隊決議,見 nmtl-web/docs/a11y/freego-scan-scope-plan-2026-09-04.md):
|
|
33
|
+
* 無障礙檢測工具 Freego 只抽取 DOM 中真實存在的 a[href]/area[href]/iframe[src]/frame[src],
|
|
34
|
+
* 且去重是完整網址字串精確比對。本元件產生的是 ?id= 明細頁連結,資料有幾筆就展開幾頁,
|
|
35
|
+
* 再乘上九個子站前綴,測試站實測達 3297 頁 / 約 24 小時。改為程式導頁後,
|
|
36
|
+
* 內容明細頁不再進入爬取佇列,只留主選單、麵包屑、網站導覽等結構性連結(仍為真 <a href>)。
|
|
37
|
+
*
|
|
38
|
+
* 可及性補償:以 role="link" 保留連結語意(非 role="button",遵循規範 03-aria-patterns §1
|
|
39
|
+
* 「導覽連結不可掛 role=button」),並自備 tabIndex 與 Enter 鍵啟動,
|
|
40
|
+
* 讀屏軟體仍會朗讀為連結、鍵盤仍可操作。焦點框由各站 a11y.scss 的
|
|
41
|
+
* [tabindex]:focus / [role='link']:focus 規則涵蓋。
|
|
42
|
+
* 已知取捨:失去中鍵/Ctrl+點擊另開分頁、右鍵複製網址等瀏覽器原生行為。
|
|
43
|
+
*/
|
|
44
|
+
var ForwardLink = function ForwardLink(_ref) {
|
|
45
|
+
var className = _ref.className,
|
|
46
|
+
linkClassName = _ref.linkClassName,
|
|
47
|
+
title = _ref.title,
|
|
48
|
+
target = _ref.target,
|
|
49
|
+
disabled = _ref.disabled,
|
|
50
|
+
children = _ref.children,
|
|
51
|
+
tip = _ref.tip,
|
|
52
|
+
onClick = _ref.onClick,
|
|
53
|
+
rest = _objectWithoutProperties(_ref, _excluded);
|
|
54
|
+
var history = useHistory();
|
|
55
|
+
var _useMemo = useMemo(function () {
|
|
56
|
+
var _rest$pathname;
|
|
57
|
+
if (disabled) return {};
|
|
58
|
+
/*
|
|
59
|
+
* 若將 search 寫在 pathname 中,意即 pathname=/asd?zxc=qwe
|
|
60
|
+
* 會導致換頁時 React route dom 無法匹配 => 空白畫面
|
|
61
|
+
* 若真有此情況發生 需把 search 提領出來
|
|
62
|
+
*/
|
|
63
|
+
var foundIndex = (_rest$pathname = rest.pathname) === null || _rest$pathname === void 0 ? void 0 : _rest$pathname.indexOf('?');
|
|
64
|
+
if (foundIndex > -1) return {
|
|
65
|
+
pathname: rest.pathname.substring(0, foundIndex),
|
|
66
|
+
search: rest.pathname.substring(foundIndex)
|
|
67
|
+
};
|
|
68
|
+
return {
|
|
69
|
+
pathname: rest.pathname || '/',
|
|
70
|
+
search: typeof rest.search === 'string' ? rest.search : queryString.stringify(rest.search)
|
|
71
|
+
};
|
|
72
|
+
}, [history, disabled, rest.pathname, rest.search]),
|
|
73
|
+
_useMemo$pathname = _useMemo.pathname,
|
|
74
|
+
pathname = _useMemo$pathname === void 0 ? '' : _useMemo$pathname,
|
|
75
|
+
_useMemo$search = _useMemo.search,
|
|
76
|
+
search = _useMemo$search === void 0 ? '' : _useMemo$search;
|
|
77
|
+
|
|
78
|
+
/* 導頁:target="_blank"(預設值)沿用原本 <a target="_blank"> 的另開分頁行為,
|
|
79
|
+
其餘 target 走 SPA 換頁。history.createHref 會自動套上 Router 的 basename
|
|
80
|
+
(各站的 contextRoot),與原本 <Link> 產出的網址一致。 */
|
|
81
|
+
var go = useCallback(function () {
|
|
82
|
+
if (onClick && onClick() === false) return;
|
|
83
|
+
var to = {
|
|
84
|
+
pathname: "".concat(getLocalePrefix(history.location.pathname)).concat(pathname),
|
|
85
|
+
search: search
|
|
86
|
+
};
|
|
87
|
+
if (target === '_blank') {
|
|
88
|
+
window.open(history.createHref(to), '_blank', 'noopener,noreferrer');
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
history.push(to);
|
|
92
|
+
}, [history, onClick, target, pathname, search]);
|
|
93
|
+
|
|
94
|
+
/* role="link" 依 ARIA APG 僅以 Enter 啟動(不綁 Space,那是 role="button" 的行為) */
|
|
95
|
+
var handleKeyDown = useCallback(function (event) {
|
|
96
|
+
if (event.key === 'Enter') {
|
|
97
|
+
event.preventDefault();
|
|
98
|
+
go();
|
|
99
|
+
}
|
|
100
|
+
}, [go]);
|
|
101
|
+
|
|
102
|
+
/* WAVE: Redundant title text — title 與連結內文相同時不輸出,避免輔具重複朗讀 */
|
|
103
|
+
var domTitle = tip || typeof children === 'string' && children === title ? undefined : title;
|
|
104
|
+
/* WCAG 3.2.x 另開新視窗預告:target="_blank" 時以 aria-label 註明 */
|
|
105
|
+
var newWindowLabel = target === '_blank' && (typeof children === 'string' || title) ? "".concat(typeof children === 'string' ? children : title).concat(getIntl().formatMessage({
|
|
106
|
+
id: 'aria.newWindow'
|
|
107
|
+
})) : undefined;
|
|
108
|
+
/* R24:aria-label 已含 title 全文時不再輸出 title 屬性——NVDA 會把 title 屬性當
|
|
109
|
+
description 接在 aria-label 之後再唸一次,造成「書名 ×2」(abo 首頁推薦卡實測) */
|
|
110
|
+
var linkTitle = newWindowLabel ? undefined : domTitle;
|
|
111
|
+
|
|
112
|
+
/* 沒有可及名稱的連結對所有使用者都無用,且會被判 Freego HM1240401C
|
|
113
|
+
(實測 ocean books?id=ART469770:某筆資料人名為空 → 連結內容全空)。
|
|
114
|
+
children 為空字串/空值且無 title 時,改以非互動元素呈現。 */
|
|
115
|
+
var namelessChildren = children === undefined || children === null || children === false || typeof children === 'string' && !children.trim();
|
|
116
|
+
var nameless = namelessChildren && !title;
|
|
117
|
+
var linkComponent = /*#__PURE__*/React__default.createElement("div", {
|
|
118
|
+
className: className
|
|
119
|
+
}, /*#__PURE__*/React__default.createElement("div", {
|
|
120
|
+
className: "forwardLink"
|
|
121
|
+
}, disabled || nameless ? /*#__PURE__*/React__default.createElement("div", {
|
|
122
|
+
title: domTitle,
|
|
123
|
+
className: classNames('forwardLink__link--disabled', linkClassName)
|
|
124
|
+
}, children) :
|
|
125
|
+
/*#__PURE__*/
|
|
126
|
+
/* linkClassName 直接掛在可聚焦元素上:消費端的 ellipsis/overflow 樣式若掛在
|
|
127
|
+
外層 className(包裹 div),會裁掉焦點框(WCAG 2.4.7 走查實測)——
|
|
128
|
+
此類樣式應改傳 linkClassName */
|
|
129
|
+
React__default.createElement("span", {
|
|
130
|
+
role: "link",
|
|
131
|
+
tabIndex: 0,
|
|
132
|
+
className: classNames('forwardLink__link', linkClassName),
|
|
133
|
+
title: linkTitle,
|
|
134
|
+
"aria-label": newWindowLabel,
|
|
135
|
+
onClick: go,
|
|
136
|
+
onKeyDown: handleKeyDown
|
|
137
|
+
}, children)));
|
|
138
|
+
if (tip) {
|
|
139
|
+
return /*#__PURE__*/React__default.createElement(Tooltip, {
|
|
140
|
+
title: tip,
|
|
141
|
+
placement: "top"
|
|
142
|
+
}, linkComponent);
|
|
143
|
+
}
|
|
144
|
+
return linkComponent;
|
|
145
|
+
};
|
|
146
|
+
ForwardLink.defaultProps = {
|
|
147
|
+
className: undefined,
|
|
148
|
+
linkClassName: undefined,
|
|
149
|
+
title: undefined,
|
|
150
|
+
target: '_blank',
|
|
151
|
+
disabled: undefined,
|
|
152
|
+
children: undefined,
|
|
153
|
+
search: undefined,
|
|
154
|
+
tip: undefined,
|
|
155
|
+
onClick: function onClick() {
|
|
156
|
+
return true;
|
|
157
|
+
}
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
/* Write props detail information and 'npm run updateStory' will help you generate stories's argTypes */
|
|
161
|
+
ForwardLink.propTypes = {
|
|
162
|
+
/** Css Name(掛在外層包裹 div;帶 overflow/ellipsis 的樣式請改用 linkClassName,否則會裁掉焦點框) */
|
|
163
|
+
className: PropTypes.string,
|
|
164
|
+
/** 直接掛在可聚焦元素上的 Css Name */
|
|
165
|
+
linkClassName: PropTypes.string,
|
|
166
|
+
/** DOM title */
|
|
167
|
+
title: PropTypes.string,
|
|
168
|
+
/** 導頁方式:'_blank' 另開分頁(預設),其餘走 SPA 換頁 */
|
|
169
|
+
target: PropTypes.oneOf(['_self', '_blank', '_parent', '_top']),
|
|
170
|
+
/** 是否取消點擊 */
|
|
171
|
+
disabled: PropTypes.bool,
|
|
172
|
+
/** 子項目 */
|
|
173
|
+
children: PropTypes.node,
|
|
174
|
+
/** 欲前往的連結 */
|
|
175
|
+
pathname: PropTypes.string.isRequired,
|
|
176
|
+
/** 欲前往連結的參數 */
|
|
177
|
+
search: PropTypes.oneOfType([PropTypes.object, PropTypes.string]),
|
|
178
|
+
/** 彈跳提示文字 */
|
|
179
|
+
tip: PropTypes.oneOfType([PropTypes.bool, PropTypes.string]),
|
|
180
|
+
/** 元件被點即時的callback,返回false會停止元件導向 */
|
|
181
|
+
onClick: PropTypes.func
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
export { ForwardLink as F };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export { F as default } from './ForwardLink-5fbd2705.js';
|
|
2
|
+
import './_rollupPluginBabelHelpers-a52356f6.js';
|
|
3
|
+
import 'react';
|
|
4
|
+
import 'prop-types';
|
|
5
|
+
import './index-b76a85f4.js';
|
|
6
|
+
import './index-b47819f3.js';
|
|
7
|
+
import 'react-router-dom';
|
|
8
|
+
import '@material-ui/core';
|
|
9
|
+
import './globalConfig';
|
|
10
|
+
import './style-inject.es-1f59c1d0.js';
|
package/lib/components/Header.js
CHANGED
|
@@ -1 +1,233 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { a as _slicedToArray } from './_rollupPluginBabelHelpers-a52356f6.js';
|
|
2
|
+
import React__default, { useState, useRef, useEffect } from 'react';
|
|
3
|
+
import PropTypes from 'prop-types';
|
|
4
|
+
import { c as classNames } from './index-b76a85f4.js';
|
|
5
|
+
import { d as debounce_1 } from './debounce-127da66c.js';
|
|
6
|
+
import { useHistory, useRouteMatch, NavLink } from 'react-router-dom';
|
|
7
|
+
import { Typography, IconButton } from '@material-ui/core';
|
|
8
|
+
import { SearchOutlined } from '@material-ui/icons';
|
|
9
|
+
import { K as KeywordSearch } from './KeywordSearch-fec33a2c.js';
|
|
10
|
+
import { S as Select } from './Select-cb3e1ba1.js';
|
|
11
|
+
import { c as checkLanguageSupport, D as Drawer, d as defaultSupportLanguage } from './Drawer-629e59c7.js';
|
|
12
|
+
import { getIntl } from './globalConfig';
|
|
13
|
+
import { s as styleInject } from './style-inject.es-1f59c1d0.js';
|
|
14
|
+
import './isObjectLike-e111475d.js';
|
|
15
|
+
import './_commonjsHelpers-70de2c37.js';
|
|
16
|
+
import 'axios';
|
|
17
|
+
import './Autocomplete-3b418e5f.js';
|
|
18
|
+
import '@material-ui/lab';
|
|
19
|
+
import './createSvgIcon-e3803ee1.js';
|
|
20
|
+
import './defaultTheme-ed7746fe.js';
|
|
21
|
+
import 'react-is';
|
|
22
|
+
import '@material-ui/styles';
|
|
23
|
+
import 'react-dom';
|
|
24
|
+
import './toConsumableArray-dbe8af76.js';
|
|
25
|
+
import './Empty-c6a44967.js';
|
|
26
|
+
import './useTheme-d16d02d9.js';
|
|
27
|
+
import './withTheme-2d778133.js';
|
|
28
|
+
|
|
29
|
+
var css_248z = "@charset \"UTF-8\";\n.header {\n display: flex;\n align-items: center;\n background: rgba(255, 255, 255, 0.6);\n background-color: rgba(255, 255, 255, 0.6);\n padding: 12px 36px !important;\n position: fixed;\n top: 0;\n z-index: 10;\n width: 100% !important;\n transition: top 0.3s ease-in-out;\n box-shadow: 0 2px 4px 0 rgba(0, 0, 0, 0.1);\n /* 呼叫端自訂工具區(如字級縮放):與語系選單同屬右側工具列 */\n}\n.header__logo {\n display: flex;\n width: -moz-fit-content !important;\n width: fit-content !important;\n margin-right: 30px !important;\n cursor: pointer;\n text-decoration: none;\n}\n.header__logo__img {\n display: flex;\n align-items: center;\n}\n.header__logo__title {\n white-space: nowrap;\n margin-left: 1rem !important;\n font-size: 1.5rem !important;\n font-weight: 700 !important;\n font-family: \"Noto Sans TC\" !important;\n}\n.header__links {\n display: flex;\n justify-content: flex-end;\n padding-right: 14px;\n}\n.header__links a {\n text-decoration: none;\n}\n.header__links--full {\n flex: 1;\n}\n.header__links__item {\n color: rgba(0, 0, 0, 0.85);\n font-size: 1.125rem !important;\n font-weight: 500 !important;\n white-space: nowrap;\n padding: 6px 14px;\n font-family: \"Noto Sans TC\" !important;\n}\n.header__links__item--active .header__links__item {\n font-weight: 800 !important;\n background: transparent;\n border-radius: 45px;\n}\n.header__links__item:hover {\n font-weight: 800 !important;\n}\n.header__language {\n min-width: 100px !important;\n}\n.header__extraTools {\n display: flex;\n align-items: center;\n margin-right: 8px;\n}\n.header__searchIcon {\n display: none !important;\n}\n@media screen and (max-width: 768px) {\n .header--smallUseSearchIcon .header__searchIcon {\n display: flex !important;\n margin-right: 10px !important;\n }\n .header--smallUseSearchIcon .keywordSearch {\n visibility: hidden;\n flex: 1;\n width: 0;\n }\n}\n.header--hide {\n top: -100px;\n}\n.header--focus .header__links {\n display: none;\n}\n.header .MuiTypography-root {\n width: 100%;\n display: flex;\n align-items: center;\n}\n.header .autocomplete {\n float: right;\n}\n.header .autocomplete .MuiAutocomplete-inputRoot[class*=MuiOutlinedInput-root] {\n padding: 1px 8px !important;\n}\n.header .keywordSearch {\n margin-right: 8px;\n}\n.header .keywordSearch--focus .autocomplete {\n width: 100% !important;\n}\n.header .keywordSearch--animation .autocomplete {\n width: 240px;\n transition: width 0.3s ease-in-out;\n}\n\n/* 避免寬度460以下炸版 */\n@media screen and (max-width: 460px) {\n .header .keywordSearch--animation .autocomplete {\n width: 100%;\n }\n}\n@media screen and (max-width: 768px) {\n .header {\n padding: 12px 15px !important;\n /* 窄畫面比照語系選單收進抽屜,避免擠壓搜尋框 */\n }\n .header__logo {\n margin-right: 16px !important;\n }\n .header__logo__title {\n display: none !important;\n }\n .header__links {\n display: none;\n }\n .header__links__item {\n font-size: 1rem !important;\n }\n .header__language {\n display: none !important;\n }\n .header__extraTools {\n display: none !important;\n }\n .header--focus .header__logo {\n display: none !important;\n }\n\n .autocomplete__icon {\n display: none !important;\n }\n}";
|
|
30
|
+
styleInject(css_248z);
|
|
31
|
+
|
|
32
|
+
var showDarkModeSwitch = false;
|
|
33
|
+
var Header = function Header(props) {
|
|
34
|
+
var title = props.title,
|
|
35
|
+
logo = props.logo,
|
|
36
|
+
locale = props.locale,
|
|
37
|
+
supportLanguages = props.supportLanguages,
|
|
38
|
+
pages = props.pages;
|
|
39
|
+
props.darkMode;
|
|
40
|
+
var typographyColor = props.typographyColor,
|
|
41
|
+
className = props.className;
|
|
42
|
+
var searchAPI = props.searchAPI,
|
|
43
|
+
searchPlaceholder = props.searchPlaceholder,
|
|
44
|
+
smallUseSearchIcon = props.smallUseSearchIcon;
|
|
45
|
+
var onSearch = props.onSearch;
|
|
46
|
+
props.setDarkMode;
|
|
47
|
+
var onLanguageChange = props.onLanguageChange,
|
|
48
|
+
onSearchIconClick = props.onSearchIconClick,
|
|
49
|
+
languageSelectLabel = props.languageSelectLabel,
|
|
50
|
+
extraTools = props.extraTools;
|
|
51
|
+
var history = useHistory();
|
|
52
|
+
var search = history.location.search;
|
|
53
|
+
var _useRouteMatch = useRouteMatch(),
|
|
54
|
+
url = _useRouteMatch.url;
|
|
55
|
+
// const { keyword } = queryString.parse(search);
|
|
56
|
+
var _useState = useState(false),
|
|
57
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
58
|
+
hideHeader = _useState2[0],
|
|
59
|
+
setHideHeader = _useState2[1];
|
|
60
|
+
var _useState3 = useState(false),
|
|
61
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
62
|
+
menuOpen = _useState4[0],
|
|
63
|
+
setMenuOpen = _useState4[1];
|
|
64
|
+
var handleScroll = useRef(debounce_1(function () {
|
|
65
|
+
return setHideHeader(window.scrollY > 100);
|
|
66
|
+
}, 10)).current;
|
|
67
|
+
useEffect(function () {
|
|
68
|
+
window.addEventListener('scroll', handleScroll);
|
|
69
|
+
return function () {
|
|
70
|
+
window.removeEventListener('scroll', handleScroll);
|
|
71
|
+
};
|
|
72
|
+
}, []);
|
|
73
|
+
useEffect(function () {
|
|
74
|
+
setMenuOpen(false);
|
|
75
|
+
}, [search]);
|
|
76
|
+
return /*#__PURE__*/React__default.createElement("div", {
|
|
77
|
+
role: "banner",
|
|
78
|
+
className: classNames('MuiPaper-root', 'header', {
|
|
79
|
+
'header--smallUseSearchIcon': smallUseSearchIcon
|
|
80
|
+
}, {
|
|
81
|
+
'header--hide': hideHeader
|
|
82
|
+
}, {
|
|
83
|
+
'header--focus': menuOpen
|
|
84
|
+
}, className)
|
|
85
|
+
}, /*#__PURE__*/React__default.createElement(NavLink, {
|
|
86
|
+
to: "/".concat(locale, "/main/home"),
|
|
87
|
+
className: "header__logo",
|
|
88
|
+
"aria-label": title ? getIntl().formatMessage({
|
|
89
|
+
id: 'aria.header.logoHomeWithTitle'
|
|
90
|
+
}, {
|
|
91
|
+
title: title
|
|
92
|
+
}) : getIntl().formatMessage({
|
|
93
|
+
id: 'aria.header.logoHome'
|
|
94
|
+
})
|
|
95
|
+
}, logo && /*#__PURE__*/React__default.createElement("div", {
|
|
96
|
+
className: "header__logo__img"
|
|
97
|
+
}, logo), !menuOpen && title && /*#__PURE__*/React__default.createElement(Typography, {
|
|
98
|
+
color: typographyColor,
|
|
99
|
+
className: "header__logo__title"
|
|
100
|
+
}, title)), searchAPI && /*#__PURE__*/React__default.createElement(KeywordSearch, {
|
|
101
|
+
animation: true
|
|
102
|
+
// keyword={keyword}
|
|
103
|
+
,
|
|
104
|
+
searchAPI: searchAPI,
|
|
105
|
+
placeholder: searchPlaceholder,
|
|
106
|
+
menuOpen: menuOpen,
|
|
107
|
+
setMenuOpen: setMenuOpen,
|
|
108
|
+
onSearch: onSearch
|
|
109
|
+
}), /*#__PURE__*/React__default.createElement("nav", {
|
|
110
|
+
className: classNames('header__links', {
|
|
111
|
+
'header__links--full': !searchAPI
|
|
112
|
+
}),
|
|
113
|
+
"aria-label": getIntl().formatMessage({
|
|
114
|
+
id: 'aria.header.navigation'
|
|
115
|
+
})
|
|
116
|
+
}, (Array.isArray(pages) ? pages : []).filter(function (_ref) {
|
|
117
|
+
var showInHeader = _ref.showInHeader;
|
|
118
|
+
return showInHeader;
|
|
119
|
+
}).map(function (_ref2, i) {
|
|
120
|
+
var _ref2$path = _ref2.path,
|
|
121
|
+
path = _ref2$path === void 0 ? '' : _ref2$path,
|
|
122
|
+
name = _ref2.name;
|
|
123
|
+
var label = /*#__PURE__*/React__default.createElement(Typography, {
|
|
124
|
+
className: "header__links__item",
|
|
125
|
+
color: typographyColor
|
|
126
|
+
}, name);
|
|
127
|
+
return path.indexOf('http') > -1 ?
|
|
128
|
+
/*#__PURE__*/
|
|
129
|
+
/* WCAG 3.2.2 外部連結(如文學好臺誌)另開新視窗需預先提示 */
|
|
130
|
+
React__default.createElement("a", {
|
|
131
|
+
key: i.toString(),
|
|
132
|
+
href: path,
|
|
133
|
+
className: "header__links__item--active",
|
|
134
|
+
target: "_blank",
|
|
135
|
+
rel: "noopener noreferrer",
|
|
136
|
+
"aria-label": "".concat(name).concat(getIntl().formatMessage({
|
|
137
|
+
id: 'aria.newWindow'
|
|
138
|
+
}))
|
|
139
|
+
}, label) : /*#__PURE__*/React__default.createElement(NavLink, {
|
|
140
|
+
key: i.toString(),
|
|
141
|
+
to: "".concat(url).concat(path),
|
|
142
|
+
activeClassName: "header__links__item--active"
|
|
143
|
+
}, label);
|
|
144
|
+
})), /*#__PURE__*/React__default.createElement(IconButton, {
|
|
145
|
+
className: "header__searchIcon",
|
|
146
|
+
"aria-label": getIntl().formatMessage({
|
|
147
|
+
id: 'aria.header.searchOpen'
|
|
148
|
+
}),
|
|
149
|
+
onClick: onSearchIconClick
|
|
150
|
+
}, /*#__PURE__*/React__default.createElement(SearchOutlined, {
|
|
151
|
+
fontSize: "large",
|
|
152
|
+
"aria-hidden": "true"
|
|
153
|
+
})), showDarkModeSwitch , extraTools && /*#__PURE__*/React__default.createElement("div", {
|
|
154
|
+
className: "header__extraTools"
|
|
155
|
+
}, extraTools), Array.isArray(supportLanguages) && supportLanguages.length > 0 && /*#__PURE__*/React__default.createElement(Select, {
|
|
156
|
+
className: "header__language",
|
|
157
|
+
ariaLabel: languageSelectLabel || getIntl().formatMessage({
|
|
158
|
+
id: 'aria.header.languageSelect'
|
|
159
|
+
}),
|
|
160
|
+
defaultValue: checkLanguageSupport({
|
|
161
|
+
language: locale,
|
|
162
|
+
supportLanguages: supportLanguages
|
|
163
|
+
}),
|
|
164
|
+
onChange: function onChange(value) {
|
|
165
|
+
return onLanguageChange(value);
|
|
166
|
+
},
|
|
167
|
+
options: supportLanguages
|
|
168
|
+
}), /*#__PURE__*/React__default.createElement(Drawer, {
|
|
169
|
+
title: title,
|
|
170
|
+
logo: logo,
|
|
171
|
+
drawerList: pages,
|
|
172
|
+
supportLanguages: supportLanguages,
|
|
173
|
+
onLanguageChange: onLanguageChange,
|
|
174
|
+
languageSelectLabel: languageSelectLabel,
|
|
175
|
+
extraTools: extraTools
|
|
176
|
+
}));
|
|
177
|
+
};
|
|
178
|
+
Header.defaultProps = {
|
|
179
|
+
className: undefined,
|
|
180
|
+
title: undefined,
|
|
181
|
+
logo: undefined,
|
|
182
|
+
locale: undefined,
|
|
183
|
+
supportLanguages: defaultSupportLanguage,
|
|
184
|
+
darkMode: false,
|
|
185
|
+
typographyColor: 'primary',
|
|
186
|
+
searchAPI: undefined,
|
|
187
|
+
searchPlaceholder: undefined,
|
|
188
|
+
smallUseSearchIcon: undefined,
|
|
189
|
+
onSearch: function onSearch() {},
|
|
190
|
+
setDarkMode: function setDarkMode() {},
|
|
191
|
+
onLanguageChange: function onLanguageChange() {},
|
|
192
|
+
onSearchIconClick: function onSearchIconClick() {},
|
|
193
|
+
languageSelectLabel: undefined,
|
|
194
|
+
extraTools: undefined
|
|
195
|
+
};
|
|
196
|
+
Header.propTypes = {
|
|
197
|
+
/** Css Name */
|
|
198
|
+
className: PropTypes.string,
|
|
199
|
+
/** 標題(通常為網站名稱) */
|
|
200
|
+
title: PropTypes.string,
|
|
201
|
+
/** 網站Logo */
|
|
202
|
+
logo: PropTypes.node,
|
|
203
|
+
/** 語系 */
|
|
204
|
+
locale: PropTypes.string,
|
|
205
|
+
/** 支援的語系 */
|
|
206
|
+
supportLanguages: PropTypes.arrayOf(PropTypes.any),
|
|
207
|
+
/** 頁面列表 */
|
|
208
|
+
pages: PropTypes.arrayOf(PropTypes.any).isRequired,
|
|
209
|
+
/** 是否為黑暗模式 */
|
|
210
|
+
darkMode: PropTypes.bool,
|
|
211
|
+
/** 文字色系() */
|
|
212
|
+
typographyColor: PropTypes.oneOf(['initial', 'inherit', 'primary', 'secondary', 'textPrimary', 'textSecondary', 'error']),
|
|
213
|
+
/** SearchBar的API */
|
|
214
|
+
searchAPI: PropTypes.string,
|
|
215
|
+
/** SearchBar的提示字 */
|
|
216
|
+
searchPlaceholder: PropTypes.string,
|
|
217
|
+
/** 是否在小畫面的時候使用SearchIcon取代KeywordSearch */
|
|
218
|
+
smallUseSearchIcon: PropTypes.bool,
|
|
219
|
+
/** SearchBar啟動搜尋的callback */
|
|
220
|
+
onSearch: PropTypes.func,
|
|
221
|
+
/** 設定黑暗模式的callback */
|
|
222
|
+
setDarkMode: PropTypes.func,
|
|
223
|
+
/** 語系變動時的callback */
|
|
224
|
+
onLanguageChange: PropTypes.func,
|
|
225
|
+
/** SearchIcon點擊時的callback */
|
|
226
|
+
onSearchIconClick: PropTypes.func,
|
|
227
|
+
/** 語言下拉的無障礙名稱(WCAG 3.3.2);未提供時使用套件內 aria.header.languageSelect */
|
|
228
|
+
languageSelectLabel: PropTypes.string,
|
|
229
|
+
/** 呼叫端自訂的工具區(如字級縮放):寬畫面顯示於語系選單之前,窄畫面隨語系一起收進抽屜 */
|
|
230
|
+
extraTools: PropTypes.node
|
|
231
|
+
};
|
|
232
|
+
|
|
233
|
+
export { Header as default };
|