Skip to content

Instantly share code, notes, and snippets.

@monkindey
Last active October 14, 2017 09:10
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save monkindey/21cc865a8a1e5febaf00ad0f11171fb3 to your computer and use it in GitHub Desktop.
Save monkindey/21cc865a8a1e5febaf00ad0f11171fb3 to your computer and use it in GitHub Desktop.
category type title
Components
Feedback
Alert

Alert component for feedback.

When To Use

  • When you need to show alert messages to users.
  • When you need a persistent static container which is closable by user actions.

API

Property Description Type Default
type Type of Alert styles, options: success, info, warning, error string info, in banner mode default is warning
closable Whether Alert can be closed boolean -
closeText Close text to show string|ReactNode -
message Content of Alert string|ReactNode -
description Additional content of Alert string|ReactNode -
onClose Callback when Alert is closed Function -
showIcon Whether to show icon boolean false, in banner mode default is true
banner Whether to show as banner boolean false
category type title
Components
Feedback
Alert

Alert component for feedback.

When To Use

  • When you need to show alert messages to users.
  • When you need a persistent static container which is closable by user actions.

API

Property Description Type Default
banner Whether to show as banner boolean false
closable Whether Alert can be closed boolean -
closeText Close text to show string|ReactNode -
description Additional content of Alert string|ReactNode -
message Content of Alert string|ReactNode -
showIcon Whether to show icon boolean false, in banner mode default is true
type Type of Alert styles, options: success, info, warning, error string info, in banner mode default is warning
onClose Callback when Alert is closed Function -
category type title
Components
Feedback
Alert

Alert component for feedback.

When To Use

  • When you need to show alert messages to users.
  • When you need a persistent static container which is closable by user actions.

API

Property Description Type Default
banner Whether to show as banner boolean false
closable Whether Alert can be closed boolean -
closeText Close text to show string|ReactNode -
description Additional content of Alert string|ReactNode -
message Content of Alert string|ReactNode -
showIcon Whether to show icon boolean false, in banner mode default is true
type Type of Alert styles, options: success, info, warning, error string info, in banner mode default is warning
onClose Callback when Alert is closed Function -
const fs = require('fs');
const remark = require('remark');
const md = fs.readFileSync('./fixtures/alert.md');
const ast = remark().parse(md);
function getCellValue(node) {
return node.children[0].children[0].value;
}
function sort(nodes) {
return nodes.sort((prev, next) => {
prev = getCellValue(prev);
next = getCellValue(next);
return prev > next;
});
}
ast.children.forEach(child => {
let staticProp = [];
// prefix with `on`
let dynamicProp = [];
if (child.type === 'table') {
// slice will create new array, so sort can affect the original array
// slice(1) cut down the thead
child.children.slice(1).forEach(node => {
let value = getCellValue(node);
if (/^on[A-Z]/.test(value)) {
dynamicProp.push(node);
} else {
staticProp.push(node);
}
});
child.children = [
child.children[0],
...sort(staticProp),
...sort(dynamicProp)
];
}
});
console.log(remark().stringify(ast));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment