-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #839 from oceanbase/dengfuping-dev
improve(design): Typography editable and editing style
- Loading branch information
Showing
8 changed files
with
253 additions
and
9 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,155 @@ | ||
import React, { useMemo, useState } from 'react'; | ||
import { CheckOutlined, HighlightOutlined } from '@oceanbase/icons'; | ||
import { Radio, Typography } from '@oceanbase/design'; | ||
|
||
const { Paragraph } = Typography; | ||
|
||
const App: React.FC = () => { | ||
const [editableStr, setEditableStr] = useState('This is an editable text.'); | ||
const [editableStrWithSuffix, setEditableStrWithSuffix] = useState( | ||
'This is a loooooooooooooooooooooooooooooooong editable text with suffix.' | ||
); | ||
const [editableStrWithSuffixStartPart, editableStrWithSuffixSuffixPart] = useMemo( | ||
() => [editableStrWithSuffix.slice(0, -12), editableStrWithSuffix.slice(-12)], | ||
[editableStrWithSuffix] | ||
); | ||
const [customIconStr, setCustomIconStr] = useState('Custom Edit icon and replace tooltip text.'); | ||
const [clickTriggerStr, setClickTriggerStr] = useState( | ||
'Text or icon as trigger - click to start editing.' | ||
); | ||
const [chooseTrigger, setChooseTrigger] = useState<('icon' | 'text')[]>(['icon']); | ||
const [customEnterIconStr, setCustomEnterIconStr] = useState( | ||
'Editable text with a custom enter icon in edit field.' | ||
); | ||
const [noEnterIconStr, setNoEnterIconStr] = useState( | ||
'Editable text with no enter icon in edit field.' | ||
); | ||
const [hideTooltipStr, setHideTooltipStr] = useState('Hide Edit tooltip.'); | ||
const [lengthLimitedStr, setLengthLimitedStr] = useState( | ||
'This is an editable text with limited length.' | ||
); | ||
|
||
const radioToState = (input: string): ('icon' | 'text')[] => { | ||
switch (input) { | ||
case 'text': | ||
return ['text']; | ||
case 'both': | ||
return ['icon', 'text']; | ||
case 'icon': | ||
return ['icon']; | ||
default: | ||
return ['icon']; | ||
} | ||
}; | ||
|
||
const stateToRadio = useMemo<string>(() => { | ||
if (chooseTrigger.includes('text')) { | ||
return chooseTrigger.includes('icon') ? 'both' : 'text'; | ||
} | ||
return 'icon'; | ||
}, [chooseTrigger]); | ||
|
||
return ( | ||
<> | ||
<div style={{ marginBottom: 12 }}> | ||
Trigger edit with:{' '} | ||
<Radio.Group | ||
onChange={e => setChooseTrigger(radioToState(e.target.value))} | ||
value={stateToRadio} | ||
> | ||
<Radio value="icon">icon</Radio> | ||
<Radio value="text">text</Radio> | ||
<Radio value="both">both</Radio> | ||
</Radio.Group> | ||
</div> | ||
<Paragraph editable={{ onChange: setEditableStr, triggerType: chooseTrigger }}> | ||
{editableStr} | ||
</Paragraph> | ||
<Paragraph | ||
editable={{ | ||
onChange: setEditableStrWithSuffix, | ||
text: editableStrWithSuffix, | ||
triggerType: chooseTrigger, | ||
}} | ||
ellipsis={{ | ||
suffix: editableStrWithSuffixSuffixPart, | ||
}} | ||
> | ||
{editableStrWithSuffixStartPart} | ||
</Paragraph> | ||
<Paragraph | ||
editable={{ | ||
icon: <HighlightOutlined />, | ||
tooltip: 'click to edit text', | ||
onChange: setCustomIconStr, | ||
triggerType: chooseTrigger, | ||
}} | ||
> | ||
{customIconStr} | ||
</Paragraph> | ||
<Paragraph | ||
editable={{ | ||
tooltip: 'click to edit text', | ||
onChange: setClickTriggerStr, | ||
triggerType: chooseTrigger, | ||
}} | ||
> | ||
{clickTriggerStr} | ||
</Paragraph> | ||
<Paragraph | ||
editable={{ | ||
icon: <HighlightOutlined />, | ||
tooltip: 'click to edit text', | ||
onChange: setCustomEnterIconStr, | ||
triggerType: chooseTrigger, | ||
enterIcon: <CheckOutlined />, | ||
}} | ||
> | ||
{customEnterIconStr} | ||
</Paragraph> | ||
<Paragraph | ||
editable={{ | ||
icon: <HighlightOutlined />, | ||
tooltip: 'click to edit text', | ||
onChange: setNoEnterIconStr, | ||
triggerType: chooseTrigger, | ||
enterIcon: null, | ||
}} | ||
> | ||
{noEnterIconStr} | ||
</Paragraph> | ||
<Paragraph | ||
editable={{ tooltip: false, onChange: setHideTooltipStr, triggerType: chooseTrigger }} | ||
> | ||
{hideTooltipStr} | ||
</Paragraph> | ||
<Paragraph | ||
editable={{ | ||
onChange: setLengthLimitedStr, | ||
triggerType: chooseTrigger, | ||
maxLength: 50, | ||
autoSize: { maxRows: 5, minRows: 3 }, | ||
}} | ||
> | ||
{lengthLimitedStr} | ||
</Paragraph> | ||
<Typography.Title editable={{ triggerType: chooseTrigger }} level={1} style={{ margin: 0 }}> | ||
h1. Ant Design | ||
</Typography.Title> | ||
<Typography.Title editable={{ triggerType: chooseTrigger }} level={2} style={{ margin: 0 }}> | ||
h2. Ant Design | ||
</Typography.Title> | ||
<Typography.Title editable={{ triggerType: chooseTrigger }} level={3} style={{ margin: 0 }}> | ||
h3. Ant Design | ||
</Typography.Title> | ||
<Typography.Title editable={{ triggerType: chooseTrigger }} level={4} style={{ margin: 0 }}> | ||
h4. Ant Design | ||
</Typography.Title> | ||
<Typography.Title editable={{ triggerType: chooseTrigger }} level={5} style={{ margin: 0 }}> | ||
h5. Ant Design | ||
</Typography.Title> | ||
</> | ||
); | ||
}; | ||
|
||
export default App; |
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,17 @@ | ||
import React from 'react'; | ||
import type { BlockProps } from 'antd/es/typography/Base'; | ||
import classNames from 'classnames'; | ||
|
||
const useClassName = (prefixCls: string, className: string, editable?: BlockProps['editable']) => { | ||
const typographyCls = classNames( | ||
prefixCls, | ||
{ | ||
[`${prefixCls}-editable-text`]: | ||
typeof editable === 'object' && editable?.triggerType?.includes('text'), | ||
}, | ||
className | ||
); | ||
return typographyCls; | ||
}; | ||
|
||
export default useClassName; |
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