Skip to content

Commit d1ea21d

Browse files
authored
fix(style): style dropdown typed list on hover (#19)
1 parent 4a8c642 commit d1ea21d

File tree

1 file changed

+42
-5
lines changed

1 file changed

+42
-5
lines changed

netlify-cms@2/packages/netlify-cms-ui-default/src/ObjectWidgetTopBar.js

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useState } from 'react';
1+
import React, { useState, useEffect } from 'react';
22
import PropTypes from 'prop-types';
33
import styled from '@emotion/styled';
44
import { css } from '@emotion/core';
@@ -87,8 +87,16 @@ const DropdownButtons = styled.button`
8787
cursor: pointer;
8888
text-align: center;
8989
90+
overflow: hidden;
91+
-moz-transition: all 0.3s;
92+
-webkit-transition: all 0.3s;
93+
transition: all 0.3s;
94+
9095
&:hover{
9196
background-color: #f6f6f9;
97+
-moz-transform: scale(1.1);
98+
-webkit-transform: scale(1.1);
99+
transform: scale(1.1);
92100
}
93101
`;
94102
const DivIntDropdownButtons = styled.div`
@@ -109,6 +117,10 @@ const IconFile = styled.div`
109117
min-height: 40px;
110118
margin: 5px auto;
111119
`;
120+
const LabelP = styled.p`
121+
margin: 0;
122+
font-size: 13px;
123+
`
112124
const AddButton = styled.button`
113125
${buttons.button}
114126
${buttons.widget}
@@ -133,6 +145,31 @@ const ObjectWidgetTopBar = ({
133145
}) => {
134146

135147
const [dropBotton, setDropBotton] = useState(false)
148+
const [typesLabel, setTypesLabel] = useState([])
149+
150+
useEffect(() => {
151+
let listMajor = []
152+
let listMinor = []
153+
if (types) {
154+
types.map((type, idx) => {
155+
const label = `${type?.get('label', type?.get('name')).toString()}`
156+
listMinor.push(`${label.substr(0, 13)}..`)
157+
listMajor.push(label)
158+
})
159+
setTypesLabel({ listMinor, listMajor, list: listMinor })
160+
}
161+
}, [])
162+
163+
const zoomInLabel = (i) => {
164+
let listZoom = [...typesLabel.listMinor]
165+
listZoom[i] = typesLabel.listMajor[i]
166+
setTypesLabel({ ...typesLabel, list: listZoom })
167+
}
168+
169+
const zoomOutLabel = (i) => {
170+
setTypesLabel({ ...typesLabel, list: typesLabel.listMinor })
171+
}
172+
136173
const renderAddUI = () => {
137174
if (!allowAdd) return null
138175
return renderTypesDropdown(types);
@@ -155,12 +192,12 @@ const ObjectWidgetTopBar = ({
155192
<Drop>
156193
<DivDropdownButtons>
157194
{types.map((type, idx) => (
158-
<DropdownButtons key={idx} onClick={() => { onAddType(type?.get('name')); setDropBotton(!dropBotton) }}>
195+
<DropdownButtons key={idx} onClick={() => { onAddType(type?.get('name')); setDropBotton(!dropBotton) }}
196+
onMouseEnter={() => zoomInLabel(idx)}
197+
onMouseLeave={() => zoomOutLabel(idx)}>
159198
{type?.get('icon', type?.get('icon'))
160199
&& <IconFile src={type?.get('icon', type?.get('icon')).toString()} />}
161-
<p style={{ margin: 0 }}>{type?.get('label', type?.get('name'))?.length > 10
162-
? `${type?.get('label', type?.get('name')).toString().substr(0, 9)}..`
163-
: type?.get('label', type?.get('name'))}</p>
200+
<LabelP>{typesLabel.list[idx]}</LabelP>
164201
</DropdownButtons>
165202
))}
166203
</DivDropdownButtons>

0 commit comments

Comments
 (0)