0.8.4 • Published 4 years ago

armory-component-ui v0.8.4

Weekly downloads
67
License
-
Repository
-
Last release
4 years ago

armory-component-ui

NPM version NPM downloads

Common components and features for GW2Armory.com and GW2AEmbeds. With data fetching, persistence, error handling, and a plethora of components for use, all out-of-the-box.

Installation

npm install armory-component-ui --save

State Management

Redux and redux-thunk are used for state management. Here is an example integration of armory-component-ui with its redux state management. Note the use of reducers.

import { Provider } from 'react-redux';
import { combineReducers, applyMiddleware, createStore } from 'redux';
import thunk from 'redux-thunk';
import { reducers, Tooltip } from 'armory-component-ui';

const store = createStore(
  // Create the root reducer.
  combineReducers(reducers),

  // Set the thunk middleware.
  applyMiddleware(thunk),
);

const App = () => (
  <Provider store={store}>
    <span>
      <div>My Other Components Here</div>
      <Tooltip />
    </span>
  </Provider>
);

Styles

Make sure to import the component styles to your application.

If you're using webpack, simply do:

import '!!style-loader!css-loader!armory-component-ui/styles.css';

This resets all loaders on this import, then applies the style and css loader.

Fonts

The menomonia and opensans fonts are used across these components. Look inside /stories/styles.css for an example font definition. All the fonts are included in the package for you to use.

Images

Copy node_modules/armory-coponent-ui/images to {WHEREYOUWANT}/images. If you are storing the images in a subdirectory (e.g: /assets/images) or on another server altogether, make sure to set document.__publicPath to the that path.

So for example if we're in a subdirectory as above, set it to document.__publicPath = '/assets';.

If rendering on the server you'll have to fake the document global variable.

Components

<CharacterPreview />

import { CharacterPreview } from 'armory-component-ui';

() => <CharacterPreview name="Quatermile" />
proptypedescriptionrequired
namestringn/ayes
classNamestringn/ano

<Gw2Skin />

import { Gw2Skin } from 'armory-component-ui';

() => <Gw2Skin id={23} />
proptypedescriptionrequired
idnumbern/ayes
countnumberSets the count which affects the name for both the <Tooltip /> and inlineText.no
sizenumberCustom size of the icon, e.g: 40 will result in a 40x40 icon.no
tooltipTextOverridestringOverrides the tooltip with custom textno
inlineText'gw2Spidy', 'wiki', stringWill show text next to the icon that links to somewhere. Passing in any string will result in linking to that string.no
classNamestringn/ano

<Gw2Title />

import { Gw2Title } from 'armory-component-ui';

() => <Gw2Title id={44} />
proptypedescriptionrequired
idnumbern/ayes

<Gw2GuildUpgrade />

import { Gw2GuildUpgrade } from 'armory-component-ui';

() => <Gw2GuildUpgrade id={44} />
proptypedescriptionrequired
idnumbern/ayes

<Gw2Item />

import { Gw2Item } from 'armory-component-ui';

() =>
  <Gw2Item
    equipped
    id={23}
    count={4}
    size={64}
    inlineText="wiki"
    upgrades={[24815]}
    infusions={[49426]}
  />
proptypedescriptionrequired
idnumbern/ayes
statsIdnumberId of the stats the item should be assigned.no
countnumberSets the count which affects the name for both the <Tooltip /> and inlineText.no
tooltipTextOverridestringOverrides the tooltip with custom textno
sizenumberCustom size of the icon, e.g: 40 will result in a 40x40 icon.no
inlineText'gw2Spidy', 'wiki', stringWill show text next to the icon that links to somewhere. Passing in any string will result in linking to that string.no
classNamestringn/ano
equippedbooleanShows 'Equipped' text at the top of the <Tooltip />.no
upgradesArray<number>Array of upgrade ids (v2/items).no
infusionsArray<number>Array of infusion ids (v2/items).no
stats{ attributes: Array<{ [attribute]: string }> }Static stats usually passed from v2/characters. See: https://wiki.guildwars2.com/wiki/API:2/characters. Generally better to just use statsId.no
upgradeCounts{ [upgradeId]: number }Consolidation of total upgrade counts.no
onClickFunctionn/ano

<Gw2Map />

import { Gw2Map } from 'armory-component-ui';

() => <Gw2Map id={549} />
proptypedescriptionrequired
idnumbern/ayes
classNamestringn/ano

<Gw2Infusion />

import { Gw2Infusion } from 'armory-component-ui';

() => <Gw2Infusion id={49426} />
proptypedescriptionrequired
idnumbern/ayes

<Gw2Upgrade />

import { Gw2Upgrade } from 'armory-component-ui';

() => <Gw2Upgrade id={24615} />
proptypedescriptionrequired
idnumbern/ayes

<Gw2Skill />

import { Gw2Skill } from 'armory-component-ui';

() => <Gw2Skill id={5493} />
proptypedescriptionrequired
idnumbern/ayes
classNamestringn/ano
tooltipTextOverridestringOverrides the tooltip with custom textno
sizenumberCustom size of the icon, e.g: 40 will result in a 40x40 icon.no
inlineText'gw2Spidy', 'wiki', stringWill show text next to the icon that links to somewhere. Passing in any string

<Gw2Specialization />

import { Gw2Specialization } from 'armory-component-ui';

() => <Gw2Specialization id={56} activeTraits={[2177, 2061, 2138]} />
proptypedescriptionrequired
idnumbern/ayes
activeTraitsArray<number>Major traits that are active.no
onTraitClick(id: number) => voidCallback function called when a trait icon is clicked.no
minorTraitClassstringClass name applied to the minor trait icons.no
majorTraitClassstringClass name applied to the major trait icons.no

<Gw2Trait />

import { Gw2Trait } from 'armory-component-ui';

() => <Gw2Trait id={229} />
proptypedescriptionrequired
idnumbern/ayes
activebooleanSets the trait to active (100% opacity).no
classNamestringn/ano
tooltipTextOverridestringOverrides the tooltip with custom textno
sizenumberCustom size of the icon, e.g: 40 will result in a 40x40 icon.no
inlineText'gw2Spidy', 'wiki', stringWill show text next to the icon that links to somewhere. Passing in any string

<ArmoryBadge />

import { ArmoryBadge } from 'armory-component-ui';

() => <ArmoryBadge hotlink />
proptypedescriptionrequired
classNamestringn/ano
hotlinkbooleanEnables the badge to have a link back to the armory.no

<Gold />

import { Gold } from 'armory-component-ui';

() => <Gold coins={12345} />
proptypedescriptionrequired
classNamestringn/ano

<LanguageProvider />

import { LanguageProvider } from 'armory-component-ui';
<LanguageProvider lang="de">
  <div>other components here</div>
</LanguageProvider>
proptypedescriptionrequired
lang'en', 'de', 'fr', 'zh', 'ru', 'es'Sets the language for all child (armory) componentsyes
childrenNoden/ayes

<PieChart />

import { PieChart } from 'armory-component-ui';

() =>
  <PieChart
    dataValues={[{
      color: 'lightgreen',
      name: 'Sylvari',
      value: 5455,
    }, {
      color: 'yellow',
      name: 'Human',
      value: 1000,
    }]}
  />
proptypedescriptionrequired
dataValuesDataValuesThe data for the chart, see the example above.yes
sizenumberThe custom size of the chart. E.g: 128 will result in a chart 128x128.no
classNamestringn/ano

<Tooltip />

Make sure to put this as high as you can in the component tree. This will show the tooltip when appropriate for other components.

import { Tooltip } from 'armory-component-ui';

() => <Tooltip />

<TooltipTrigger />

Shows the tooltip when mouse over/touch start. Hides the tooltip when mouse leave/touch end.

import { TooltipTrigger } from 'armory-component-ui';

() =>
  <TooltipTrigger
    data="Cool Tooltip"
    type="items"
  >
    <span>Hover Over Me</span>
  </TooltipTrigger>
proptypedescriptionrequired
childrenNoden/ayes
type'items', 'amulets', 'trait', 'skill', 'achievement', 'guildUpgrade'Type of tooltip to show. Only affects the tooltip if the data sent is an Object.no
datastring, ObjectData to send to the <Tooltip />.no
onMouseEnterFunctionn/ano
onMouseLeaveFunctionn/ano

Helpers

reducers: { [string]: Function }

Object of reducer functions, pass this into your combineReducers function.

import { reducers } from 'armory-component-ui';
import { Provider } from 'react-redux';
import { combineReducers, createStore } from 'redux';

const store = createStore(
  combineReducers(reducers),
);

const App = () => (
  <Provider store={store}>
    <div />
  </Provider>
);

actions: Object

Standard redux actions that fetch gw2 data.

import { connect } from 'react-redux';
import { actions } from 'armory-component-ui';

const mapStateToProps = (state) => ({
  skills: state.skills,
});

const mapDispatchToProps = {
  fetch: actions.fetchSkills,
};

connect(mapStateToProps, mapDispatchToProps)(
  class SomeSkill extends React.Component {
    componentDidMount () {
      this.props.fetch([1139, 5490, 5495]);
    }

    render () {
      const skill = this.props.skills[1139];

      return (
        <div>
          {skill.name}
        </div>
      );
    }
  }
);
actionNamearguments
fetchSkillsArray<number>
fetchAchievementCategoriesArray<number>'all'
fetchAchievementGroupsArray<number>'all'
fetchAchievementsArray<number>
fetchAmuletsArray<number>
fetchCurrenciesArray<number>
fetchGuildUpgradesArray<number>
fetchItemStatsArray<number>
fetchMapsArray<number>
fetchMaterialsArray<number>
fetchPetsArray<number>
fetchProfessionsArray<number>
fetchPvpSeasonsArray<number>
fetchAmuletsArray<number>
fetchSkillsArray<number>
fetchSkinsArray<number>
fetchSpecializationsArray<number>
fetchTitlesArray<number>
fetchTraitsArray<number>
fetchWorldsArray<number>
fetchCalculatedItemStatsArray<{ id: number, itemId: number, type: string, rarity: string, level: number }>

markup(text: string, useTagName: boolean)

By default the class will be a class inside the armory-component-ui/styles.css:

import { markup } from 'armory-component-ui';

const text = 'Gain a boon upon casting a <c=@abilitytype>glyph</c> based on your attunement. <c=@abilitytype>Glyphs</c> gain reduced recharge.';

markup(text);
// <span dangerouslySetInnerHTML={{ __html: 'Gain a boon upon casting a <span class="abilitytype">glyph</span> based on your attunement. <span class="DxsxS">Glyphs</span> gain reduced recharge.' }}>

If you pass useTagName as true, the class on the element will be the @colourname text, for example:

import { markup } from 'armory-component-ui';

const text = 'Gain a boon upon casting a <c=@abilitytype>glyph</c> based on your attunement. <c=@abilitytype>Glyphs</c> gain reduced recharge.';

markup(text, true);
// <span dangerouslySetInnerHTML={{ __html: 'Gain a boon upon casting a <span class="abilitytype">glyph</span> based on your attunement. <span class="abilitytype">Glyphs</span> gain reduced recharge.' }}>

persistToLocalStorage(boolean)

By default data will be persisted to local storage. You can turn this off by doing the following:

import { persistToLocalStorage } from 'armory-component-ui';

persistToLocalStorage(false);
// Local storage data persistence is now turned off.

forceCacheClearOnNextRun(string: key)

Will force api cache to be cleared next time the code executes. Use a unique key every time you want to clear the cache.

import { forceCacheClearOnNextRun } from 'armory-component-ui;';

forceCacheClearOnNextRun('1');

Local Development

git clone git@github.com:madou/armory-component-ui.git
cd armory-component-ui
yarn # See https://yarnpkg.com/lang/en/docs/install/
npm start # Runs react-storybook
npm run tdd # Runs tests in watch mode

Building Docs

npm run build-storybook

Releasing

# Make sure the changelog has your changes under Unreleased
# Be on master branch
npm version major|minor|patch

© 2015-present gw2armory.com

0.8.4

4 years ago

0.8.3-1

4 years ago

0.8.3

4 years ago

0.8.2

4 years ago

0.8.1

6 years ago

0.8.0

6 years ago

0.7.0

6 years ago

0.6.1

7 years ago

0.6.0

7 years ago

0.5.2

7 years ago

0.5.1

7 years ago

0.5.0

7 years ago

0.4.3

7 years ago

0.4.2

7 years ago

0.4.1

7 years ago

0.4.0

7 years ago

0.3.3

7 years ago

0.3.2

7 years ago

0.3.1

7 years ago

0.3.0

7 years ago

0.2.0

7 years ago

0.1.2

7 years ago