File tree Expand file tree Collapse file tree 8 files changed +72
-6
lines changed
exampleSite/content/docs/guide Expand file tree Collapse file tree 8 files changed +72
-6
lines changed Original file line number Diff line number Diff line change 77 const optionsElement = switcher . nextElementSibling ;
88 optionsElement . classList . toggle ( 'hx:hidden' ) ;
99
10- // Calculate position of language options element
10+ // Calculate the position of a language options element.
1111 const switcherRect = switcher . getBoundingClientRect ( ) ;
12- const translateY = switcherRect . top - window . innerHeight - 15 ;
13- optionsElement . style . transform = `translate3d( ${ switcherRect . left } px, ${ translateY } px, 0)` ;
12+
13+ // Must be called before optionsElement.clientWidth.
1414 optionsElement . style . minWidth = `${ Math . max ( switcherRect . width , 50 ) } px` ;
15+
16+ const isOnTop = switcher . dataset . location === 'top' ;
17+ const isRTL = document . body . dir === 'rtl'
18+
19+ // Stuck on the left side of the switcher.
20+ let translateX = switcherRect . left ;
21+
22+ if ( isOnTop && ! isRTL || ! isOnTop && isRTL ) {
23+ // Stuck on the right side of the switcher.
24+ translateX = switcherRect . right - optionsElement . clientWidth ;
25+ }
26+
27+ // Stuck on the top of the switcher.
28+ let translateY = switcherRect . top - window . innerHeight - 15 ;
29+
30+ if ( isOnTop ) {
31+ // Stuck on the bottom of the switcher.
32+ translateY = switcherRect . top - window . innerHeight + 180 ;
33+ }
34+
35+ optionsElement . style . transform = `translate3d(${ translateX } px, ${ translateY } px, 0)` ;
1536 } ) ;
1637 } ) ;
1738
Original file line number Diff line number Diff line change 6969 - name: Theme Toggle
7070 params:
7171 type: theme-toggle
72+ label: true # optional, default is false
73+ ` ` `
74+ 6. مُبدِّل اللغة
75+ ` ` ` yaml
76+ - name: مُبدِّل اللغة
77+ params:
78+ type: language-switch
79+ label: true # optional, default is false
80+ icon: "globe-alt" # optional, default is "translate"
7281 ` ` `
7382
7483این آیتمهای منو را میتوان با تنظیم پارامتر `weight` مرتب کرد.
Original file line number Diff line number Diff line change 6969 - name: Theme Toggle
7070 params:
7171 type: theme-toggle
72+ label: true # optional, default is false
73+ ` ` `
74+ 6. 言語スイッチャー
75+ ` ` ` yaml
76+ - name: 言語スイッチャー
77+ params:
78+ type: language-switch
79+ label: true # optional, default is false
80+ icon: "globe-alt" # optional, default is "translate"
7281 ` ` `
7382
7483これらのメニュー項目は `weight` パラメータを設定することで並べ替えられます。
Original file line number Diff line number Diff line change @@ -69,6 +69,15 @@ There are different types of menu items:
6969 - name: Theme Toggle
7070 params:
7171 type: theme-toggle
72+ label: true # optional, default is false
73+ ` ` `
74+ 6. Language Switcher
75+ ` ` ` yaml
76+ - name: Language Switcher
77+ params:
78+ type: language-switch
79+ label: true # optional, default is false
80+ icon: "globe-alt" # optional, default is "translate"
7281 ` ` `
7382
7483These menu items can be sorted by setting the `weight` parameter.
Original file line number Diff line number Diff line change 6969 - name: Theme Toggle
7070 params:
7171 type: theme-toggle
72+ label: true # optional, default is false
73+ ` ` `
74+ 6. 语言切换器
75+ ` ` ` yaml
76+ - name: 语言切换器
77+ params:
78+ type: language-switch
79+ label: true # optional, default is false
80+ icon: "globe-alt" # optional, default is "translate"
7281 ` ` `
7382
7483通过设置 `weight` 参数可以调整菜单项的排序。
Original file line number Diff line number Diff line change 11{{- $page := .context -}}
2+ {{- $iconName := .iconName | default "globe-alt" -}}
3+ {{- $iconHeight := .iconHeight | default 12 -}}
4+ {{- $location := .location -}}
5+
6+ {{- $class := .class | default "hx:h-7 hx:px-2 hx:text-xs hx:text-gray-600 hx:transition-colors hx:dark:text-gray-400 hx:hover:bg-gray-100 hx:hover:text-gray-900 hx:dark:hover:bg-primary-100/5 hx:dark:hover:text-gray-50" -}}
27
38{{- $grow := .grow -}}
49{{- $hideLabel := .hideLabel | default false -}}
1015 < button
1116 title ="{{ $changeLanguage }} "
1217 data-state ="closed "
13- class ="hextra-language-switcher hx:cursor-pointer hx:h-7 hx:rounded-md hx:px-2 hx:text-left hx:text-xs hx:font-medium hx:text-gray-600 hx:transition-colors hx:dark:text-gray-400 hx:hover:bg-gray-100 hx:hover:text-gray-900 hx:dark:hover:bg-primary-100/5 hx:dark:hover:text-gray-50 hx:grow "
18+ data-location ="{{ $location }} "
19+ class ="hextra-language-switcher hx:cursor-pointer hx:rounded-md hx:text-left hx:font-medium {{ $class }} hx:grow "
1420 type ="button "
1521 aria-label ="{{ $changeLanguage }} "
1622 >
1723 < div class ="hx:flex hx:items-center hx:gap-2 hx:capitalize ">
18- {{- partial "utils/icon" (dict "name" "globe-alt" "attributes" "height=12" ) -}}
24+ {{- partial "utils/icon" (dict "name" $iconName "attributes" (printf "height=%d" $iconHeight) ) -}}
1925 {{- if not $hideLabel }}< span > {{ site.Language.LanguageName }}</ span > {{ end -}}
2026 </ div >
2127 </ button >
Original file line number Diff line number Diff line change 77 {{ end -}}
88{{- end -}}
99
10+ {{- $page := . -}}
1011{{- $iconHeight := 24 -}}
1112
1213< div class ="hextra-nav-container hx:sticky hx:top-0 hx:z-20 hx:w-full hx:bg-transparent hx:print:hidden ">
3940 </ a >
4041 {{- else if eq .Params.type "theme-toggle" -}}
4142 {{- partial "theme-toggle.html" (dict "iconHeight" $iconHeight "class" "hx:p-2" "hideLabel" (not .Params.label)) -}}
43+ {{- else if eq .Params.type "language-switch" -}}
44+ {{- partial "language-switch" (dict "context" $page "grow" false "hideLabel" (not .Params.label) "iconName" (.Params.icon | default "translate") "iconHeight" $iconHeight "location" "top" "class" "hx:p-2") -}}
4245 {{- else -}}
4346 {{- $active := or ($currentPage.HasMenuCurrent "main" .) ($currentPage.IsMenuCurrent "main" .) -}}
4447 {{- $activeClass := cond $active "hx:font-medium" "hx:text-gray-600 hx:hover:text-gray-800 hx:dark:text-gray-400 hx:dark:hover:text-gray-200" -}}
Original file line number Diff line number Diff line change 11{{- $hideLabel := .hideLabel -}}
22{{- $iconHeight := .iconHeight | default 12 -}}
3- {{- $class := .class | default "hx:px-2 hx:text-xs hx:hover:bg-gray-100 hx:hover:text-gray-900 hx:dark:hover:bg-primary-100/5 hx:dark:hover:text-gray-50 hx:font-medium hx:text-gray-600 hx:transition-colors hx:dark:text-gray-400" -}}
3+ {{- $class := .class | default "hx:h-7 hx: px-2 hx:text-xs hx:hover:bg-gray-100 hx:hover:text-gray-900 hx:dark:hover:bg-primary-100/5 hx:dark:hover:text-gray-50 hx:font-medium hx:text-gray-600 hx:transition-colors hx:dark:text-gray-400" -}}
44
55{{- $changeTheme := (T "changeTheme") | default "Change theme" -}}
66{{- $light := (T "light") | default "Light" -}}
You can’t perform that action at this time.
0 commit comments