Skip to content

Commit

Permalink
✨ feat: 添加自定义排序的能力
Browse files Browse the repository at this point in the history
  • Loading branch information
arvinxx committed Apr 9, 2021
1 parent 49f257d commit bb70bf4
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 11 deletions.
25 changes: 19 additions & 6 deletions packages/journey-map/src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import type { FC, CSSProperties } from 'react';
import type { FC, CSSProperties, ReactNode } from 'react';
import cls from 'classnames';

import Stage from './Stages';
Expand All @@ -8,7 +8,7 @@ import Actions from './Actions';
import Thoughts from './Thoughts';

import { JourneyMapStore, useJourneyMap } from './useJourneyMap';
import type { Config, JourneyMapData } from './types';
import type { Config, JourneyMapData, SectionType } from './types';

import './styles.less';

Expand Down Expand Up @@ -47,6 +47,22 @@ const JourneyMap: FC<JourneyMapProps> = ({
}) => {
const store = useJourneyMap({ data, onChange, title, config });

const sections: Record<SectionType, ReactNode> = {
action: <Actions />,
stage: <Stage />,
emotion: <Chart />,
thought: <Thoughts />,
chance: <div />,
painSpot: <div />,
};

const arrange = store.config?.arrange || [
'stage',
'action',
'emotion',
'thought',
];

return (
<JourneyMapStore.Provider value={store}>
<div
Expand All @@ -57,10 +73,7 @@ const JourneyMap: FC<JourneyMapProps> = ({
<div className="avx-journey-map-title">{store.title}</div>
) : null}
<div className="avx-journey-map-content">
<Stage />
<Actions />
<Chart />
<Thoughts />
{arrange.map((a) => sections[a])}
</div>
</div>
</JourneyMapStore.Provider>
Expand Down
6 changes: 3 additions & 3 deletions packages/journey-map/src/types/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export interface UserAction {
painSpot?: string[];
}

type Section =
export type SectionType =
| 'stage'
| 'action'
| 'emotion'
Expand All @@ -94,9 +94,9 @@ export interface Config {
/**
* 每个部分的高度
*/
height?: Record<Partial<Section>, number>;
height?: Record<Partial<SectionType>, number>;
/**
* section 的排序
*/
arrange?: Partial<Section>[];
arrange?: Partial<SectionType>[];
}
4 changes: 2 additions & 2 deletions packages/journey-map/src/useJourneyMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export const useJourneyMap = ({
data,
onChange,
title: initTitle,
config: initConfig,
config: initConfig = {},
}: StoreParams) => {
const defaultJourneyMap: JourneyMapData = { stages: [], actions: {} };

Expand All @@ -21,7 +21,7 @@ export const useJourneyMap = ({
);

const [title, setTitle] = useState<string>(initTitle);
const [config, setConfig] = useState(initConfig || {});
const [config, setConfig] = useState(initConfig);

const [store, setStore] = hook;
/**
Expand Down

0 comments on commit bb70bf4

Please sign in to comment.